-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench.py
90 lines (72 loc) · 2.03 KB
/
bench.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import json
import os
import subprocess
RESULTS_FILE = "results.txt"
RUN_SCRIPTS = {
"cpp": "./cpp/run.sh",
"python": "./python/run.sh",
"python3": "./python/run_python3.sh",
"kotlin": "./kotlin/run.sh",
"kotlin_jit": "./kotlin/run_jit.sh",
"kotlin_jit_5": "./kotlin/run_jit_5.sh",
"cython_bfs": "./cython/run.sh",
"cython_full": "./cython/run_full.sh",
"rust": "./rust/run.sh",
}
# RESULTS_FILE = "results-rust.txt"
# RUN_SCRIPTS = {
# "cpp": "./cpp/run.sh",
# "cpp1": "./cpp/run.sh",
# "cpp2": "./cpp/run.sh",
# "rust": "./rust/run.sh",
# "rust1": "./rust/run.sh",
# "rust2": "./rust/run.sh",
# }
def extract_tags(lines):
result = {}
for line in lines.split('\n'):
if "=" in line:
k, v = line.split("=")
result[k] = v
return result
def run_benchmark(name, map_name):
path = 'txt-maps/{}'.format(map_name)
script = RUN_SCRIPTS[name]
stdout = subprocess.check_output([script, path])
tags = extract_tags(stdout)
tags['map'] = map_name
tags['name'] = name
print(tags)
return tags
def write_to_file(data):
f = open(RESULTS_FILE, 'a')
f.write(json.dumps(data) + '\n')
f.close()
def get_map_tags(map_name):
f = open('maps/{}'.format(map_name.replace(".txt", ".json")))
data = json.load(f)
return {
'nodes': len(data['sites']),
'edges': len(data['rivers']),
}
def all_benchmarks():
# clean the file
f = open(RESULTS_FILE, 'w')
f.close()
files = os.listdir('txt-maps/')
# files = [
# 'edinburgh-10000.txt',
# 'icfp-coauthors-pj.txt',
# 'vancouver.txt',
# 'oxford-10000.txt',
# ]
for f in reversed(files):
print('')
map_tags = get_map_tags(f)
print('{} -> {}'.format(f, map_tags))
for name in sorted(RUN_SCRIPTS.keys()):
tags = run_benchmark(name, f)
tags.update(map_tags)
write_to_file(tags)
all_benchmarks()
# run_benchmark('kotlin_jit', 'gothenburg-sparse.txt')