Skip to content

Instantly share code, notes, and snippets.

@cjmcgraw
Created August 19, 2014 00:05
Show Gist options
  • Save cjmcgraw/ffa8c1b6e6a1eeeb2106 to your computer and use it in GitHub Desktop.
Save cjmcgraw/ffa8c1b6e6a1eeeb2106 to your computer and use it in GitHub Desktop.
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