Created
August 19, 2014 00:05
-
-
Save cjmcgraw/ffa8c1b6e6a1eeeb2106 to your computer and use it in GitHub Desktop.
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
from itertools import ifilter | |
from time import time | |
def time_it(func, *args, **kwargs): | |
def func_wrapper(*args, **kwargs): | |
t1 = time() | |
func(*args, **kwargs) | |
t2 = time() | |
print("Function Executed in: {} seconds".format(t2 - t1)) | |
return func_wrapper | |
@time_it | |
def naive_max_odd(data): | |
return max([x for x in data if x % 2 == 1]) | |
@time_it | |
def max_odd(data): | |
return max(ifilter(lambda x: x%2, data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment