Navigation

Source code for sympy.utilities.timeutils

"""Simple tools for timing functions' execution, when IPython is not available. """from__future__importprint_function,divisionimporttimeitimportmathfromsympy.core.compatibilityimportu_scales=[1e0,1e3,1e6,1e9]_units=[u('s'),u('ms'),u('\u03bcs'),u('ns')]

[docs]deftimed(func,setup="pass",limit=None):"""Adaptively measure execution time of a function. """timer=timeit.Timer(func,setup=setup)repeat,number=3,1foriinrange(1,10):iftimer.timeit(number)>=0.2:breakeliflimitisnotNoneandnumber>=limit:breakelse:number*=10time=min(timer.repeat(repeat,number))/numberiftime>0.0:order=min(-int(math.floor(math.log10(time))//3),3)else:order=3return(number,time,time*_scales[order],_units[order])# Code for doing inline timings of recursive algorithms.