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
Post a Comment