aboutsummaryrefslogtreecommitdiff
path: root/entries/zgrannan/fib2.py
blob: 64672ef3a84d7b499bee97fc0f904387e2ad92ca (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python3

import sys
import time

def fib(n):
    if n <= 1:
        time.sleep(n)
    else:
        fib(n - 1)
        fib(n - 2)


start = time.time_ns()
try:
    n = int(sys.argv[-1])
except ValueError:
    n = 5
fib(n)
now = time.time_ns()
result = round((now - start) / 1000000000)
print(f"fib({n}) = {result}")