[PATCH 01 of 10 v5] util: introduce timer()
Simon Farnsworth
simonfar at fb.com
Wed Feb 15 22:06:51 UTC 2017
# HG changeset patch
# User Simon Farnsworth <simonfar at fb.com>
# Date 1487188439 28800
# Wed Feb 15 11:53:59 2017 -0800
# Node ID 36ad17f00656ef853e0bd7b79e9cd98b58c92a16
# Parent afaf3c2b129c8940387fd9928ae4fdc28259d13c
util: introduce timer()
As documented for timeit.default_timer, there are better timers available for
performance measures on some platforms. These timers don't have a set epoch,
and thus are only useful for interval measurements, but have higher
resolution, and thus get you a better measurement overall.
Use the same selection logic as Python's timeit.default_timer. This is a
platform clock on Python 2 and early Python 3, and time.perf_counter on Python
3.3 and later (where time.perf_counter is introduced as the best timer to use).
diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1203,8 +1203,13 @@
if pycompat.osname == 'nt':
checkosfilename = checkwinfilename
+ timer = time.clock
else:
checkosfilename = platform.checkosfilename
+ timer = time.time
+
+if safehasattr(time, "perf_counter"):
+ timer = time.perf_counter
def makelock(info, pathname):
try:
More information about the Mercurial-devel
mailing list