-
Notifications
You must be signed in to change notification settings - Fork 4
/
render_table.py
132 lines (104 loc) · 4.17 KB
/
render_table.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from collections import defaultdict
def parse_and_render():
with open("benchmark_data") as f:
lines = f.readlines()
# key_type, name, size
benchmarks_point = {}
benchmarks_string = {}
for line in lines[2:]:
components = line.split()
name = components[0]
time = components[2]
name_components = name.split("/")
if len(name_components) != 4:
continue
bench_name = name_components[0]
bench_key_type = name_components[1]
tree_type = name_components[2]
bench_size = int(name_components[3])
time_components = time.split("±")
if "µs" in time:
base = 1000
elif "ns" in time:
base = 1
elif "ms" in time:
base = 1000 * 1000
elif "ps" in time:
base = 1 / 1000
elif "s" in time:
base = 1000 * 1000 * 1000
else:
print(f"unknown time unit {time}")
continue
time_ns = float(time_components[0]) * base
time_obj = {
"time_ns": time_ns,
"time_disp": time,
}
if bench_key_type == "Point":
cur_benchmarks = benchmarks_point
elif bench_key_type == "String":
cur_benchmarks = benchmarks_string
else:
continue
if bench_name not in cur_benchmarks:
cur_benchmarks[bench_name] = {bench_size: {tree_type: time_obj}}
elif bench_size not in cur_benchmarks[bench_name]:
cur_benchmarks[bench_name][bench_size] = {tree_type: time_obj}
else:
cur_benchmarks[bench_name][bench_size][tree_type] = time_obj
print("## Point benchmark")
print_benchmark(benchmarks_point)
print("## String benchmark")
print_benchmark(benchmarks_string)
def print_benchmark(benchmarks):
# render benchmarks as markdown table
print("| name | size | btree | bptree | speed factor |")
print("| - | - | - | - | - |")
benchmarks_with_bulk = defaultdict(defaultdict)
for bench_name in benchmarks:
for bench_size in benchmarks[bench_name]:
if len(benchmarks[bench_name][bench_size]) == 3:
# print in a new table
benchmarks_with_bulk[bench_name][bench_size] = benchmarks[bench_name][
bench_size
]
continue
if "btree" not in benchmarks[bench_name][bench_size]:
bptree_time = benchmarks[bench_name][bench_size]["bptree"]["time_ns"]
bptree_time_disp = benchmarks[bench_name][bench_size]["bptree"][
"time_disp"
]
print(f"| {bench_name} | {bench_size} | - | {bptree_time_disp} | - |")
else:
btree_time = benchmarks[bench_name][bench_size]["btree"]["time_ns"]
btree_time_disp = benchmarks[bench_name][bench_size]["btree"][
"time_disp"
]
bptree_time = benchmarks[bench_name][bench_size]["bptree"]["time_ns"]
bptree_time_disp = benchmarks[bench_name][bench_size]["bptree"][
"time_disp"
]
speed_factor = btree_time / bptree_time
print(
f"| {bench_name} | {bench_size} | {btree_time_disp} | {bptree_time_disp} | {speed_factor:.2f} |"
)
print("| name | size | type | time |")
print("| - | - | - | - |")
last_bench_name = None
for bench_name in benchmarks_with_bulk:
for bench_size in benchmarks_with_bulk[bench_name]:
benchmarks = list(benchmarks_with_bulk[bench_name][bench_size].items())
benchmarks.sort()
for bench_type, time in benchmarks:
name = None
if (bench_name, bench_size) == last_bench_name:
name = ""
size = ""
else:
last_bench_name = (bench_name, bench_size)
name = bench_name
size = bench_size
print(f"| {name} | {size} | {bench_type} | {time['time_disp']}")
if __name__ == "__main__":
parse_and_render()