[PATCH 1 of 8 v3] mercurial: use timeit.default_timer for interval measurement
Simon Farnsworth
simonfar at fb.com
Sun Feb 12 03:16:57 EST 2017
On 11/02/2017 23:40, Bryan O'Sullivan wrote:
>
> On Fri, Feb 10, 2017 at 1:06 PM, Simon Farnsworth <simonfar at fb.com
> <mailto: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
>
It ends up more complex than that, because Python 3.3 introduces
time.perf_counter(), which ties into platform specific performance
counters where available to get a very high resolution clock.
Something like:
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1203,8 +1203,12 @@ def checkwinfilename(path):
if pycompat.osname == 'nt':
checkosfilename = checkwinfilename
+ timer = time.clock
else:
checkosfilename = platform.checkosfilename
+ timer = time.time
+if util.safehasattr(time, perf_counter):
+ timer = time.perf_counter
def makelock(info, pathname):
try:
--
Simon Farnsworth
More information about the Mercurial-devel
mailing list