Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. def exec_time(func):
  2. def inner(*args, **kwargs):
  3. import time
  4. st = time.time()
  5. ret = func(*args, **kwargs)
  6. et = time.time() - st
  7. print "execution time %s seconds" %(et)
  8. return ret
  9.  
  10. return inner
  11.  
  12. @exec_time
  13. def fabonacci(n):
  14. if n == 0:
  15. return 0
  16. elif n == 1:
  17. return 1
  18.  
  19. a, b = 0, 1
  20. i = 2
  21. while i < n:
  22. a, b = b, a + b
  23. i += 1
  24.  
  25. return b
  26.  
  27. if __name__ == "__main__":
  28. print fabonacci(20)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement