Last active
July 3, 2018 06:31
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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