timefunc

astroquery.utils.timer.timefunc(num_tries=1, verbose=True)[source]

Decorator to time a function or method.

Parameters
num_triesint, optional

Number of calls to make. Timer will take the average run time.

verbosebool, optional

Extra log information.

Returns
ttfloat

Average run time in seconds.

result

Output(s) from the function.

Examples

To add timer to time numpy.log for 100 times with verbose output:

import numpy as np
from astroquery.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