comparison contrib/perf.py @ 42364:a09829e14fc0

perf: make sure to explicitly disable any profiler after the first iteration The current code work, because of some edge behavior of the `profile` class. We make it explicit that the profiler is not in effect more than once.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Thu, 23 May 2019 19:05:39 +0200
parents 3293086ff663
children c2d10506725c
comparison
equal deleted inserted replaced
42363:b02f3aa2fab5 42364:a09829e14fc0
272 """dummy context manager""" 272 """dummy context manager"""
273 def __enter__(self): 273 def __enter__(self):
274 pass 274 pass
275 def __exit__(self, *args): 275 def __exit__(self, *args):
276 pass 276 pass
277
278 NOOPCTX = noop()
277 279
278 def gettimer(ui, opts=None): 280 def gettimer(ui, opts=None):
279 """return a timer function and formatter: (timer, formatter) 281 """return a timer function and formatter: (timer, formatter)
280 282
281 This function exists to gather the creation of formatter in a single 283 This function exists to gather the creation of formatter in a single
403 gc.collect() 405 gc.collect()
404 results = [] 406 results = []
405 begin = util.timer() 407 begin = util.timer()
406 count = 0 408 count = 0
407 if profiler is None: 409 if profiler is None:
408 profiler = noop() 410 profiler = NOOPCTX
409 for i in xrange(prerun): 411 for i in xrange(prerun):
410 if setup is not None: 412 if setup is not None:
411 setup() 413 setup()
412 func() 414 func()
413 keepgoing = True 415 keepgoing = True
415 if setup is not None: 417 if setup is not None:
416 setup() 418 setup()
417 with profiler: 419 with profiler:
418 with timeone() as item: 420 with timeone() as item:
419 r = func() 421 r = func()
422 profiler = NOOPCTX
420 count += 1 423 count += 1
421 results.append(item[0]) 424 results.append(item[0])
422 cstop = util.timer() 425 cstop = util.timer()
423 # Look for a stop condition. 426 # Look for a stop condition.
424 elapsed = cstop - begin 427 elapsed = cstop - begin