Mercurial > hg
comparison contrib/perf.py @ 42359:563cd9a72682
perf: add a `pre-run` option
sometimes, the initial run is necessary to warm some cache that are not relevant
for the current measurement. We add a new `perf.pre-run` option to specify a
number of run of the benchmark logic that will happens before measurement are
taken.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Tue, 21 May 2019 15:08:06 +0200 |
parents | caebe5e7f4bd |
children | 3293086ff663 |
comparison
equal
deleted
inserted
replaced
42358:45c18f7345c1 | 42359:563cd9a72682 |
---|---|
12 worst, median average. If not set only the best timing is reported | 12 worst, median average. If not set only the best timing is reported |
13 (default: off). | 13 (default: off). |
14 | 14 |
15 ``presleep`` | 15 ``presleep`` |
16 number of second to wait before any group of runs (default: 1) | 16 number of second to wait before any group of runs (default: 1) |
17 | |
18 ``pre-run`` | |
19 number of run to perform before starting measurement. | |
17 | 20 |
18 ``run-limits`` | 21 ``run-limits`` |
19 Control the number of runs each benchmark will perform. The option value | 22 Control the number of runs each benchmark will perform. The option value |
20 should be a list of `<time>-<numberofrun>` pairs. After each run the | 23 should be a list of `<time>-<numberofrun>` pairs. After each run the |
21 conditions are considered in order with the following logic: | 24 conditions are considered in order with the following logic: |
236 ) | 239 ) |
237 configitem(b'perf', b'parentscount', | 240 configitem(b'perf', b'parentscount', |
238 default=mercurial.configitems.dynamicdefault, | 241 default=mercurial.configitems.dynamicdefault, |
239 ) | 242 ) |
240 configitem(b'perf', b'all-timing', | 243 configitem(b'perf', b'all-timing', |
244 default=mercurial.configitems.dynamicdefault, | |
245 ) | |
246 configitem(b'perf', b'pre-run', | |
241 default=mercurial.configitems.dynamicdefault, | 247 default=mercurial.configitems.dynamicdefault, |
242 ) | 248 ) |
243 configitem(b'perf', b'run-limits', | 249 configitem(b'perf', b'run-limits', |
244 default=mercurial.configitems.dynamicdefault, | 250 default=mercurial.configitems.dynamicdefault, |
245 ) | 251 ) |
339 continue | 345 continue |
340 limits.append((time_limit, run_limit)) | 346 limits.append((time_limit, run_limit)) |
341 if not limits: | 347 if not limits: |
342 limits = DEFAULTLIMITS | 348 limits = DEFAULTLIMITS |
343 | 349 |
344 t = functools.partial(_timer, fm, displayall=displayall, limits=limits) | 350 prerun = getint(ui, b"perf", b"pre-run", 0) |
351 t = functools.partial(_timer, fm, displayall=displayall, limits=limits, | |
352 prerun=prerun) | |
345 return t, fm | 353 return t, fm |
346 | 354 |
347 def stub_timer(fm, func, setup=None, title=None): | 355 def stub_timer(fm, func, setup=None, title=None): |
348 if setup is not None: | 356 if setup is not None: |
349 setup() | 357 setup() |
366 (3.0, 100), | 374 (3.0, 100), |
367 (10.0, 3), | 375 (10.0, 3), |
368 ) | 376 ) |
369 | 377 |
370 def _timer(fm, func, setup=None, title=None, displayall=False, | 378 def _timer(fm, func, setup=None, title=None, displayall=False, |
371 limits=DEFAULTLIMITS): | 379 limits=DEFAULTLIMITS, prerun=0): |
372 gc.collect() | 380 gc.collect() |
373 results = [] | 381 results = [] |
374 begin = util.timer() | 382 begin = util.timer() |
375 count = 0 | 383 count = 0 |
384 for i in xrange(prerun): | |
385 if setup is not None: | |
386 setup() | |
387 func() | |
376 keepgoing = True | 388 keepgoing = True |
377 while keepgoing: | 389 while keepgoing: |
378 if setup is not None: | 390 if setup is not None: |
379 setup() | 391 setup() |
380 with timeone() as item: | 392 with timeone() as item: |