Skip to content

Instantly share code, notes, and snippets.

@foxbunny
Last active October 19, 2019 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxbunny/90f5cdcfde4329c3ed30148867d0ec82 to your computer and use it in GitHub Desktop.
Save foxbunny/90f5cdcfde4329c3ed30148867d0ec82 to your computer and use it in GitHub Desktop.
from time import time
def fib(x):
if x in (0, 1):
return x
fib1 = 0
fib2 = 1
current = 1
for i in range(2, x + 1):
current = fib1 + fib2
fib1 = fib2
fib2 = current
return current
start = time()
last_result = 0
for _ in range(10000):
for i in range(1, 41):
last_result = fib(i)
print(f"Time taken: {round((time() - start) * 1000)}ms")
print(f"Last result: {last_result}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment