Created
November 19, 2016 13:13
-
-
Save lucasc896/d060b54a014a2d0aebe36c9eec6be8d5 to your computer and use it in GitHub Desktop.
Simple time decorator
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
| import math | |
| import time | |
| def timeit(func): | |
| def wrap(*args, **kwargs): | |
| start = time.time() | |
| func_returned_value = func(*args, **kwargs) | |
| end = time.time() | |
| print "Function {} returned in {} secs".format(func.__name__, | |
| end-start) | |
| return func_returned_value | |
| return wrap | |
| def calculate(): | |
| output = [] | |
| for x in xrange(1,10): | |
| output.append(sub_calc(x)) | |
| return len(output) * max(output) / sum(output) | |
| @timeit | |
| def sub_calc(y): | |
| return math.log(y) * y ** 0.5 | |
| print calculate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment