Skip to content

Instantly share code, notes, and snippets.

@rbpasker
Created June 19, 2013 19:31
Show Gist options
  • Save rbpasker/5817288 to your computer and use it in GitHub Desktop.
Save rbpasker/5817288 to your computer and use it in GitHub Desktop.
import time
class uTimer(object):
def __enter__(self):
self.begin_time=time.time()
self.end_time=0.0
self.delta=0.0
def __exit__(self, type, value, tb):
self.end_time=time.time()
self.delta = self.end_time - self.begin_time
def fib(n):
if n==0: return 1
if n==1: return 1
return fib(n-1)+fib(n-2)
t=uTimer()
for i in range(1,40):
with t:
print i,fib(i)
print "Time was %f" % t.delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment