Mercurial > hg
comparison contrib/perf.py @ 31397:8f5ed8fa39f8
perf: perform a garbage collection before each iteration
Currently, no explicit garbage collection is performed when running
the microbenchmarks in `hg perf`. I think this is wrong because
garbage collection can have a significant impact on execution times.
And, if gc is triggered via the default heuristics, it will
fire effectively randomly during subsequent benchmark iterations
due to variable amount of garbage left over from previous runs.
Running a gc before invoking the measured function will help ensure
state is more consistent across all iterations.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 13 Mar 2017 18:16:42 -0700 |
parents | 5a9e4dc8e4fd |
children | 413b44003462 |
comparison
equal
deleted
inserted
replaced
31396:ab3e9eab754f | 31397:8f5ed8fa39f8 |
---|---|
18 # - make perf command for recent feature work correctly with early | 18 # - make perf command for recent feature work correctly with early |
19 # Mercurial | 19 # Mercurial |
20 | 20 |
21 from __future__ import absolute_import | 21 from __future__ import absolute_import |
22 import functools | 22 import functools |
23 import gc | |
23 import os | 24 import os |
24 import random | 25 import random |
25 import sys | 26 import sys |
26 import time | 27 import time |
27 from mercurial import ( | 28 from mercurial import ( |
187 | 188 |
188 def stub_timer(fm, func, title=None): | 189 def stub_timer(fm, func, title=None): |
189 func() | 190 func() |
190 | 191 |
191 def _timer(fm, func, title=None): | 192 def _timer(fm, func, title=None): |
193 gc.collect() | |
192 results = [] | 194 results = [] |
193 begin = util.timer() | 195 begin = util.timer() |
194 count = 0 | 196 count = 0 |
195 while True: | 197 while True: |
196 ostart = os.times() | 198 ostart = os.times() |