| 1 |
import time |
| 2 |
import sys |
| 3 |
|
| 4 |
|
| 5 |
def fibonacci(n): |
| 6 |
if n == 0 or n == 1: |
| 7 |
return 1 |
| 8 |
return fibonacci(n - 1) + fibonacci(n - 2) |
| 9 |
|
| 10 |
|
| 11 |
MILLIS = 1000 |
| 12 |
MICROS = MILLIS * 1000 |
| 13 |
NANOS = MICROS * 1000 |
| 14 |
|
| 15 |
|
| 16 |
def benchmark(): |
| 17 |
depth = int(sys.argv[1]) |
| 18 |
for line in sys.stdin: |
| 19 |
iters = int(line.strip()) |
| 20 |
|
| 21 |
# Setup |
| 22 |
|
| 23 |
start = time.perf_counter() |
| 24 |
for x in range(iters): |
| 25 |
fibonacci(depth) |
| 26 |
end = time.perf_counter() |
| 27 |
|
| 28 |
# Teardown |
| 29 |
|
| 30 |
delta = end - start |
| 31 |
nanos = int(delta * NANOS) |
| 32 |
print("%d" % nanos) |
| 33 |
sys.stdout.flush() |
| 34 |
|
| 35 |
|
| 36 |
benchmark() |