Python timeit or custom Timer for production -


we using custom timer class (sample given below) compute , log time taken various pieces of modules in our tornado app. exploring timeit module , wonder if should make use of instead.

i understand timeit used ad-hoc testing of piece of code. but, our scenario got log execution time every time method/ piece of code called, in our logs.

i find following points on timeit limiting blending in our current app code:

  • it expects string function call. makes weird call function every time string, passing timeit.
  • i don't find direct method return value of method when pass function timeit. there stack overflow discussion same. but, looks more workaround , parsing tuple every time sounds clumsy.

should stick our custom timer class? if not, how include timeit code, without disrupting code?

any appreciated! thank in advance.

sample timer class

import time class timer(object):     def __init__(self, ...):         ...     def __enter__(self):         self.start = time.time()         return self     def __exit__(self, *args):         self.end = time.time()         self.interval = self.end - self.start         print self.interval 


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -