Last active
August 29, 2015 14:05
-
-
Save JamesHovious/fb22f2b70c48aa674c5d to your computer and use it in GitHub Desktop.
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 timer(f): | |
| """ | |
| Decorator to time the execution of a function | |
| :param f: The function to be timed | |
| :return: The time in seconds that it took for the function to execute | |
| """ | |
| def timing_function(): | |
| ts = time() | |
| f() | |
| te = time() | |
| total_time = (te - ts) | |
| print '\n', "Exceution time : ", total_time, '\n' | |
| timing_function.__name__ = f.__name__ | |
| return timing_function | |
| # Sample usage | |
| @timer | |
| def calc(): | |
| i = 0 | |
| while i < 1000: | |
| i += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment