Created
December 12, 2016 06:58
-
-
Save Gerschel/2397e65fd894884c2d6ccba21ec2a194 to your computer and use it in GitHub Desktop.
Simple function timer; Python
This file contains 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
#!python3 | |
import time | |
def func_timer(func, *args): | |
""" | |
Input: function without parenthesis with any number of functions | |
Output: Dictionary with Minimum, Maximum and Average times over 10000 calls | |
Example: func_timer(add, 1, 2) | |
""" | |
count = 0 | |
results = [] | |
while count < 10000: | |
before_time = time.time() | |
func(*args) | |
after_time = time.time() | |
results.append(after_time - before_time) | |
count += 1 | |
return {"Minimum time": min(results), | |
"Max time": max(results), | |
"Average time": sum(results) / len(results) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment