[PATCH 1 of 8 v3] mercurial: use timeit.default_timer for interval measurement

Bryan O'Sullivan bos at serpentine.com
Sat Feb 11 18:40:11 EST 2017


On Fri, Feb 10, 2017 at 1:06 PM, Simon Farnsworth <simonfar at fb.com> wrote:

> # Parent  1f51b4658f21bbb797e922d155c1046eddccf91d
> mercurial: use timeit.default_timer for interval measurement
>
> In Python 2.6 and later, timeit.default_timer() provides the highest
> resolution timer for profiling and performance measurement, but without a
> specified epoch (on some platforms, epoch is Python start time).
>
> Switch interval measures from time.time() to timeit.default_timer() to
> exploit this.
>

There's a fair bit of unused code in timeit that is unnecessary to pull in,
and loading modules has a cost.

Here's a better version:

--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1203,8 +1203,10 @@ def checkwinfilename(path):

 if pycompat.osname == 'nt':
     checkosfilename = checkwinfilename
+    timer = time.clock
 else:
     checkosfilename = platform.checkosfilename
+    timer = time.time

 def makelock(info, pathname):
     try:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170211/3a6ed499/attachment.html>


More information about the Mercurial-devel mailing list