Show More
@@ -19,6 +19,7 | |||
|
19 | 19 | # Mercurial |
|
20 | 20 | |
|
21 | 21 | from __future__ import absolute_import |
|
22 | import contextlib | |
|
22 | 23 | import functools |
|
23 | 24 | import gc |
|
24 | 25 | import os |
@@ -273,20 +274,28 def gettimer(ui, opts=None): | |||
|
273 | 274 | def stub_timer(fm, func, title=None): |
|
274 | 275 | func() |
|
275 | 276 | |
|
277 | @contextlib.contextmanager | |
|
278 | def timeone(): | |
|
279 | r = [] | |
|
280 | ostart = os.times() | |
|
281 | cstart = util.timer() | |
|
282 | yield r | |
|
283 | cstop = util.timer() | |
|
284 | ostop = os.times() | |
|
285 | a, b = ostart, ostop | |
|
286 | r.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
|
287 | ||
|
276 | 288 | def _timer(fm, func, title=None, displayall=False): |
|
277 | 289 | gc.collect() |
|
278 | 290 | results = [] |
|
279 | 291 | begin = util.timer() |
|
280 | 292 | count = 0 |
|
281 | 293 | while True: |
|
282 | ostart = os.times() | |
|
283 | cstart = util.timer() | |
|
294 | with timeone() as item: | |
|
284 | 295 | r = func() |
|
296 | count += 1 | |
|
297 | results.append(item[0]) | |
|
285 | 298 | cstop = util.timer() |
|
286 | ostop = os.times() | |
|
287 | count += 1 | |
|
288 | a, b = ostart, ostop | |
|
289 | results.append((cstop - cstart, b[0] - a[0], b[1]-a[1])) | |
|
290 | 299 | if cstop - begin > 3 and count >= 100: |
|
291 | 300 | break |
|
292 | 301 | if cstop - begin > 10 and count >= 3: |
General Comments 0
You need to be logged in to leave comments.
Login now