Last active
October 19, 2019 18:52
-
-
Save foxbunny/90f5cdcfde4329c3ed30148867d0ec82 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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