[PATCH V2] perf: add historical portability for util.timer
Philippe Pepiot
philippe.pepiot at logilab.fr
Wed Apr 5 16:14:47 UTC 2017
# HG changeset patch
# User Philippe Pepiot <philippe.pepiot at logilab.fr>
# Date 1491391351 -7200
# Wed Apr 05 13:22:31 2017 +0200
# Node ID c0231296470330eeae91058b9a3d7a6785e16cbe
# Parent 04ec317b81280c189fcea33a05c8cbbac3c186b1
# Available At https://hg.logilab.org/users/ppepiot/hg
# hg pull https://hg.logilab.org/users/ppepiot/hg -r c02312964703
perf: add historical portability for util.timer
util.timer has been introduced in ae5d60bb and used in perf.py since 22fbca1d.
For historical portability, use locally defined timer.
diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -67,6 +67,14 @@ def safehasattr(thing, attr):
setattr(util, 'safehasattr', safehasattr)
# for "historical portability":
+# use locally defined timer instead of util.timer, because util.timer has been
+# available since ae5d60bb70c9
+if safehasattr(time, 'perf_counter'):
+ timer = time.perf_counter
+else:
+ 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
@@ -193,13 +201,13 @@ def stub_timer(fm, func, title=None):
def _timer(fm, func, title=None):
gc.collect()
results = []
- begin = util.timer()
+ begin = timer()
count = 0
while True:
ostart = os.times()
- cstart = util.timer()
+ cstart = timer()
r = func()
- cstop = util.timer()
+ cstop = timer()
ostop = os.times()
count += 1
a, b = ostart, ostop
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:867:
> 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:867:
> r.revision(r.node(x))
don't covert rev to node before passing to revision(nodeorrev)
[1]
More information about the Mercurial-devel
mailing list