aboutsummaryrefslogtreecommitdiff
path: root/benches/benchmarks/external_process.py
blob: 376c4756ba90a3937d18986a2e20b4900cc0ffd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import sys


def fibonacci(n):
    if n == 0 or n == 1:
        return 1
    return fibonacci(n - 1) + fibonacci(n - 2)


MILLIS = 1000
MICROS = MILLIS * 1000
NANOS = MICROS * 1000


def benchmark():
    depth = int(sys.argv[1])
    for line in sys.stdin:
        iters = int(line.strip())

        # Setup

        start = time.perf_counter()
        for x in range(iters):
            fibonacci(depth)
        end = time.perf_counter()

        # Teardown

        delta = end - start
        nanos = int(delta * NANOS)
        print("%d" % nanos)
        sys.stdout.flush()


benchmark()