Patchwork [2,of,8] contrib/perf: offer perf.stub to only run one loop

login
register
mail settings
Submitter timeless@mozdev.org
Date Dec. 8, 2015, 7:07 a.m.
Message ID <0efb6e25627f511eb00f.1449558443@waste.org>
Download mbox | patch
Permalink /patch/11925/
State Accepted
Headers show

Comments

timeless@mozdev.org - Dec. 8, 2015, 7:07 a.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1449250890 0
#      Fri Dec 04 17:41:30 2015 +0000
# Node ID 0efb6e25627f511eb00f7be5745332d2ccf2ac58
# Parent  0738d7fdc6720959d5bb49cda16d7da62d240c7b
contrib/perf: offer perf.stub to only run one loop

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -28,8 +28,15 @@ 
     ui.fout = ui.ferr
     # get a formatter
     fm = ui.formatter('perf', opts)
+    # stub function, runs code only once instead of in a loop
+    # experimental config: perf.stub
+    if ui.configbool("perf", "stub"):
+        return functools.partial(stub_timer, fm), fm
     return functools.partial(_timer, fm), fm
 
+def stub_timer(fm, func, title=None):
+    func()
+
 def _timer(fm, func, title=None):
     results = []
     begin = time.time()