Decorator to time a function or method.
Parameters: | num_tries : int, optional
verbose : bool, optional
|
---|---|
Returns: | tt : float
result
|
Examples
To add timer to time numpy.log for 100 times with verbose output:
import numpy as np
from astropy.utils.timer import timefunc
@timefunc(100)
def timed_log(x):
return np.log(x)
To run the decorated function above:
>>> t, y = timed_log(100)
INFO: timed_log took 9.29832458496e-06 s on AVERAGE for 100 call(s). [...]
>>> t
9.298324584960938e-06
>>> y
4.6051701859880918