Created
June 19, 2013 19:31
-
-
Save rbpasker/5817288 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
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