-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgenerate_benchmark_summaries.py
143 lines (120 loc) · 3.63 KB
/
generate_benchmark_summaries.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
133
134
135
136
137
138
139
140
141
142
143
"""
Small utility to take pytest-benchmark results and update our README.md with
them.
"""
import sys
import json
from datetime import datetime
from pytest_benchmark.utils import slugify
from humanmark import Fragment, load, HTMLBlock, Header, Text, Paragraph, dump, \
Image, BlockQuote
def main(argv):
with open('benchmark.json') as src:
j = json.load(src)
groups = {}
for benchmark in j['benchmarks']:
groups.setdefault(benchmark['group'], []).append(benchmark)
readme_summaries = Fragment()
for group_name, result in groups.items():
result.sort(key=lambda v: v['stats']['min'])
readme_summaries.extend((
Header(3, children=[Text(group_name)]),
))
row = result[0]
if 'file' in row['extra_info']:
readme_summaries.extend((
Paragraph(children=[
Text(
f'Sample file is {row["extra_info"]["file_size"]}'
' bytes.'
)
]),
))
readme_summaries.extend((
Paragraph(children=[
# Not sure why the CLI generates an extra prefixed '-' on
# the filename.
Image(
f'histograms/-{slugify(group_name)}.svg',
title=f'Histogram for {group_name}.'
)
])
))
readme_summaries.extend((
Paragraph(children=[
Text(
'| library '
'| min (ms) '
'| max (ms) '
'| mean (ms) '
'|\n'
),
Text(
'| ------- '
'| -------- '
'| -------- '
'| --------- '
'|\n'
),
*(
Text(
f'| {v["name"]} '
f'| {v["stats"]["min"] * 1000:.4f} '
f'| {v["stats"]["max"] * 1000:.4f} '
f'| {v["stats"]["mean"] * 1000:.4f} '
f'|\n'
)
for v in result
)
]),
))
with open('README.md') as src:
readme = load(src)
start = readme.find_one(
HTMLBlock,
f=lambda block: block.content == (
'<!-- start_performance_block -->\n'
)
)
end = readme.find_one(
HTMLBlock,
f=lambda block: block.content == '<!-- end_performance_block -->\n'
)
# Erase all the content between the open and closing blocks.
node = start.next
while node:
if node == end:
break
node = node.delete()
start.append_sibling(readme_summaries)
start = readme.find_one(
HTMLBlock,
f=lambda block: block.content == (
'<!-- start_last_updated_block -->\n'
)
)
end = readme.find_one(
HTMLBlock,
f=lambda block: block.content == (
'<!-- end_last_updated_block -->\n'
)
)
node = start.next
while node:
if node == end:
break
node = node.delete()
start.append_sibling(
Fragment(children=[
BlockQuote(children=[
Text(
':grey_exclamation: Benchmarks regenerated on '
f'{datetime.utcnow().strftime("%Y-%m-%d")}'
)
])
])
)
with open('README.md', 'w') as out:
dump(readme, out)
if __name__ == '__main__':
sys.exit(main(sys.argv))