util: introduce timer()
authorSimon Farnsworth <simonfar@fb.com>
Wed, 15 Feb 2017 11:53:59 -0800
changeset 30974 ae5d60bb70c9
parent 30973 e5363cb96233
child 30975 22fbca1d11ed
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).
mercurial/util.py
--- a/mercurial/util.py	Thu Dec 22 02:38:53 2016 +0100
+++ b/mercurial/util.py	Wed Feb 15 11:53:59 2017 -0800
@@ -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: