-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkbenchtab
executable file
·48 lines (40 loc) · 1.83 KB
/
mkbenchtab
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
#!/usr/bin/python
import sys
import re
BENCH_PATTERN = re.compile(r'''
^test\ ([A-Za-z_][A-Za-z0-9_]*)(?:::tests)?::strategy::
([A-Za-z_][A-Za-z0-9_]*)::bench_([A-Za-z0-9_]+)\ *
\.\.\.\ +bench:\ *([0-9]+)\ ns/iter\ \(\+/-\ ([0-9]+)\)
''', re.X)
benches = {} # [category][strategy][column]
best = {} # [category][column]
for line in sys.stdin:
m = BENCH_PATTERN.match(line)
if not m: continue
category, strategy, column, avg, std = m.groups()
avg = int(avg)
std = int(std)
benches.setdefault(category, {}).setdefault(strategy, {})[column] = '%s (%s)' % (avg, std), avg
bestpercol = best.setdefault(category, {})
if column not in bestpercol or bestpercol[column] > avg:
bestpercol[column] = avg
for category, bestcolumns in best.items():
for column, bestavg in bestcolumns.items():
for columns in benches[category].values():
if column in columns and columns[column][1] < bestavg * 1.05:
columns[column] = '**%s**' % columns[column][0], columns[column][1]
def natural_key(key):
return [int(i) if i.isdigit() else i.lower() for i in re.split(r'([0-9]+)', key)]
for category, rows in benches.items():
print '## `%s`' % category
columns = list(set().union(*[i.keys() for i in rows.values()]))
columns.sort(key=natural_key)
print 'Strategy | %s' % ' | '.join('`%s`' % i for i in columns)
print '---------|-%s' % '-|-'.join('-%s-' % ('-'*len(i)) for i in columns)
rows = list(rows.items())
rows.sort(key=lambda (k,_): (k == 'best', # best last
not k.lower().startswith('naive'), # naive first
natural_key(k)))
for strategy, results in rows:
print '`%s` | %s' % (strategy, ' | '.join(results.get(i, ('N/A',))[0] for i in columns))
print