Skip to content

Instantly share code, notes, and snippets.

@jimmybot
Created October 19, 2015 23:10
Show Gist options
  • Save jimmybot/3400668da8c847cc2e9f to your computer and use it in GitHub Desktop.
Save jimmybot/3400668da8c847cc2e9f to your computer and use it in GitHub Desktop.
def logger(fn):
start = time()
fn()
end = time()
print("time taken was: ", end - start)
return inner
def memoize(fn):
memory = {}
def fn2(*args):
if args in memory:
return memory[args]
else:
ret = fn(*args)
memory[ret]
return ret
return fn2
newfn = memoize(calculationthattakesalongtimefactorial)
newfn(99)
newfn(99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment