changeset 40680:9d88ae5c635b

perf: add a `setup` argument to run code outside of the timed section With this new argument, it is possible to perform special setup and cleanup outside of code actually timed. This is useful to provide more accurate benchmark.
author Boris Feld <boris.feld@octobus.net>
date Mon, 19 Nov 2018 22:55:07 +0000
parents 20d2fd6036ed
children c0a1686d9391
files contrib/perf.py
diffstat 1 files changed, 4 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/perf.py	Mon Nov 19 23:02:29 2018 +0000
+++ b/contrib/perf.py	Mon Nov 19 22:55:07 2018 +0000
@@ -275,7 +275,7 @@
     displayall = ui.configbool(b"perf", b"all-timing", False)
     return functools.partial(_timer, fm, displayall=displayall), fm
 
-def stub_timer(fm, func, title=None):
+def stub_timer(fm, func, setup=None, title=None):
     func()
 
 @contextlib.contextmanager
@@ -289,12 +289,14 @@
     a, b = ostart, ostop
     r.append((cstop - cstart, b[0] - a[0], b[1]-a[1]))
 
-def _timer(fm, func, title=None, displayall=False):
+def _timer(fm, func, setup=None, title=None, displayall=False):
     gc.collect()
     results = []
     begin = util.timer()
     count = 0
     while True:
+        if setup is not None:
+            setup()
         with timeone() as item:
             r = func()
         count += 1