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

login
register
mail settings
Submitter Simon Farnsworth
Date Feb. 12, 2017, 8:16 a.m.
Message ID <6352b6c0-084d-0119-fcbb-4f76753b1154@fb.com>
Download mbox | patch
Permalink /patch/18423/
State Changes Requested
Headers show

Comments

Simon Farnsworth - Feb. 12, 2017, 8:16 a.m.
On 11/02/2017 23:40, Bryan O'Sullivan wrote:
>
> On Fri, Feb 10, 2017 at 1:06 PM, Simon Farnsworth <simonfar@fb.com
> <mailto:simonfar@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:
Bryan O'Sullivan - Feb. 12, 2017, 9:32 p.m.
On Sun, Feb 12, 2017 at 12:16 AM, Simon Farnsworth <simonfar@fb.com> wrote:

> 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.
>

Ah yes. That looks cool.

Patch

--- 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: