Patchwork [V3] perf: add historical portability for util.timer

login
register
mail settings
Submitter Philippe Pepiot
Date April 6, 2017, 12:56 p.m.
Message ID <2311313dc03e7de84432.1491483385@sh71.tls.logilab.fr>
Download mbox | patch
Permalink /patch/19977/
State Accepted
Headers show

Comments

Philippe Pepiot - April 6, 2017, 12:56 p.m.
# HG changeset patch
# User Philippe Pepiot <philippe.pepiot@logilab.fr>
# Date 1491482502 -7200
#      Thu Apr 06 14:41:42 2017 +0200
# Node ID 2311313dc03e7de84432c396a5f8eefccb8e0267
# Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
# Available At https://hg.logilab.org/users/ppepiot/hg
#              hg pull https://hg.logilab.org/users/ppepiot/hg -r 2311313dc03e
perf: add historical portability for util.timer

util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
For historical portability, forcibly define util.timer in perf.py
Yuya Nishihara - April 6, 2017, 1:15 p.m.
On Thu, 06 Apr 2017 14:56:25 +0200, Philippe Pepiot wrote:
> # HG changeset patch
> # User Philippe Pepiot <philippe.pepiot@logilab.fr>
> # Date 1491482502 -7200
> #      Thu Apr 06 14:41:42 2017 +0200
> # Node ID 2311313dc03e7de84432c396a5f8eefccb8e0267
> # Parent  04ec317b81280c189fcea33a05c8cbbac3c186b1
> # Available At https://hg.logilab.org/users/ppepiot/hg
> #              hg pull https://hg.logilab.org/users/ppepiot/hg -r 2311313dc03e
> perf: add historical portability for util.timer

Queued this, thanks.

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -67,6 +67,16 @@  def safehasattr(thing, attr):
 setattr(util, 'safehasattr', safehasattr)
 
 # for "historical portability":
+# define util.timer forcibly, because util.timer has been available
+# since ae5d60bb70c9
+if safehasattr(time, 'perf_counter'):
+    util.timer = time.perf_counter
+elif os.name == 'nt':
+    util.timer = time.clock
+else:
+    util.timer = time.time
+
+# for "historical portability":
 # use locally defined empty option list, if formatteropts isn't
 # available, because commands.formatteropts has been available since
 # 3.2 (or 7a7eed5176a4), even though formatting itself has been
diff --git a/tests/test-check-code.t b/tests/test-check-code.t
--- a/tests/test-check-code.t
+++ b/tests/test-check-code.t
@@ -9,7 +9,7 @@  New errors are not allowed. Warnings are
 
   $ hg locate -X contrib/python-zstandard -X hgext/fsmonitor/pywatchman |
   > sed 's-\\-/-g' | xargs "$check_code" --warnings --per-file=0 || false
-  contrib/perf.py:859:
+  contrib/perf.py:869:
    >             r.revision(r.node(x))
    don't covert rev to node before passing to revision(nodeorrev)
   Skipping i18n/polib.py it has no-che?k-code (glob)
diff --git a/tests/test-contrib-perf.t b/tests/test-contrib-perf.t
--- a/tests/test-contrib-perf.t
+++ b/tests/test-contrib-perf.t
@@ -165,7 +165,7 @@  Check perf.py for historical portability
   $ (hg files -r 1.2 glob:mercurial/*.c glob:mercurial/*.py;
   >  hg files -r tip glob:mercurial/*.c glob:mercurial/*.py) |
   > "$TESTDIR"/check-perf-code.py contrib/perf.py
-  contrib/perf.py:859:
+  contrib/perf.py:869:
    >             r.revision(r.node(x))
    don't covert rev to node before passing to revision(nodeorrev)
   [1]