-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark.py
More file actions
53 lines (38 loc) · 1.02 KB
/
benchmark.py
File metadata and controls
53 lines (38 loc) · 1.02 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import timeit
BENCHMARK_PATH = 'examples/benchmark/'
ITERATE_COUNT = 5
LANGUAGES = [
("hobby", "./hobbyc", ".hby"),
("lua", "lua", ".lua"),
("python", "python3", ".py"),
("wren", "wren", ".wren"),
]
BENCHMARKS = [
"fib",
]
times = {}
def run_script(language, benchmark):
global times
print("---")
print(language[0].upper() + ":")
results = []
path = BENCHMARK_PATH + benchmark + language[2]
for i in range(ITERATE_COUNT):
print(f"BENCH {i}")
t = timeit.Timer(
f"run(['{language[1]}', '{path}'])",
setup="from subprocess import run")
results.append(t.timeit(1))
sum = 0
for i in results:
sum += i
times[language[0]] = sum / len(results)
def run_benchmark(benchmark):
global times
for i in LANGUAGES:
run_script(i, benchmark)
print(f"{benchmark.upper()} RESULTS")
for i in LANGUAGES:
print(f"{i[0].title()} average:\t{round(times[i[0]] * 1000)}ms")
times = {}
run_benchmark("fib")