##// END OF EJS Templates
perf: extract the timing of a section in a context manager...
Boris Feld -
r40179:acf560bc default
parent child Browse files
Show More
@@ -19,6 +19,7
19 # Mercurial
19 # Mercurial
20
20
21 from __future__ import absolute_import
21 from __future__ import absolute_import
22 import contextlib
22 import functools
23 import functools
23 import gc
24 import gc
24 import os
25 import os
@@ -273,20 +274,28 def gettimer(ui, opts=None):
273 def stub_timer(fm, func, title=None):
274 def stub_timer(fm, func, title=None):
274 func()
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 def _timer(fm, func, title=None, displayall=False):
288 def _timer(fm, func, title=None, displayall=False):
277 gc.collect()
289 gc.collect()
278 results = []
290 results = []
279 begin = util.timer()
291 begin = util.timer()
280 count = 0
292 count = 0
281 while True:
293 while True:
282 ostart = os.times()
294 with timeone() as item:
283 cstart = util.timer()
284 r = func()
295 r = func()
296 count += 1
297 results.append(item[0])
285 cstop = util.timer()
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 if cstop - begin > 3 and count >= 100:
299 if cstop - begin > 3 and count >= 100:
291 break
300 break
292 if cstop - begin > 10 and count >= 3:
301 if cstop - begin > 10 and count >= 3:
General Comments 0
You need to be logged in to leave comments. Login now