Skip to content

Instantly share code, notes, and snippets.

@cftang0827
Last active July 3, 2018 06:31
Show Gist options
  • Save cftang0827/1b7603da043bd02c4fb417077ddaed3d to your computer and use it in GitHub Desktop.
Save cftang0827/1b7603da043bd02c4fb417077ddaed3d to your computer and use it in GitHub Desktop.
The simple code that help you to estimate the computing time of the target function and get the same return value compare with origin function
def function_time(func, arg=()):
'''
The simple code that can estimate the computing time of the function and
return the same output of original one
:param func: The reference of the function you may want to estimate time
:param arg: The arguments of function, the default is ()
:return: Return original output of the function
'''
t1 = timeit.default_timer()
output = func(*arg)
t2 = timeit.default_timer() - t1
print('Time elasped of function {}: {} sec'.format(func.__name__, round(t2, 3)))
return output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment