perf: add historical portability for util.timer
authorPhilippe Pepiot <philippe.pepiot@logilab.fr>
Thu, 06 Apr 2017 14:41:42 +0200
changeset 31823 f6d77af84ef3
parent 31822 fde4822b0102
child 31824 4804644489cf
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
contrib/perf.py
tests/test-check-code.t
tests/test-contrib-perf.t
--- a/contrib/perf.py	Wed Apr 05 15:31:08 2017 -0700
+++ b/contrib/perf.py	Thu Apr 06 14:41:42 2017 +0200
@@ -67,6 +67,16 @@
 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
--- a/tests/test-check-code.t	Wed Apr 05 15:31:08 2017 -0700
+++ b/tests/test-check-code.t	Thu Apr 06 14:41:42 2017 +0200
@@ -9,7 +9,7 @@
 
   $ 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 convert rev to node before passing to revision(nodeorrev)
   Skipping i18n/polib.py it has no-che?k-code (glob)
--- a/tests/test-contrib-perf.t	Wed Apr 05 15:31:08 2017 -0700
+++ b/tests/test-contrib-perf.t	Thu Apr 06 14:41:42 2017 +0200
@@ -165,7 +165,7 @@
   $ (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 convert rev to node before passing to revision(nodeorrev)
   [1]