Skip to content

Instantly share code, notes, and snippets.

@mo-xiaoming
Created February 6, 2020 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mo-xiaoming/8c2732ac8c721a6e0d8e825df745b767 to your computer and use it in GitHub Desktop.
Save mo-xiaoming/8c2732ac8c721a6e0d8e825df745b767 to your computer and use it in GitHub Desktop.
Grouping google benchmark result
#!/usr/bin/env python3
"""
Usage: ./a.out --benchmark_format=json | ./cmp_gbm.py
from
bench_fastmod/16/32 176 ns 171 ns 3972393
bench_fastmod/16/128 192 ns 190 ns 3620738
bench_fastmod/16/224 195 ns 192 ns 3614277
bench_fastmod/64/32 484 ns 478 ns 1626646
bench_fastmod/64/128 456 ns 449 ns 1376393
bench_fastmod/64/224 490 ns 483 ns 1431184
to
16/32
bench_fastmod 153.89ns 100.00%
bench_fastmod16 139.52ns 90.66%
bench_fastmod4 153.68ns 99.86%
bench_mod 198.32ns 128.87%
16/128
bench_fastmod 148.41ns 100.00%
bench_fastmod16 139.52ns 94.01%
bench_fastmod4 142.18ns 95.80%
bench_mod 186.52ns 125.68%
"""
import json
import sys
funs = set()
args = set()
data = {}
for bm in json.loads(sys.stdin.read())['benchmarks']:
fn, *rest = bm['name'].split('/')
funs.add(fn)
args.add(tuple(int(i) for i in rest))
data[bm['name']] = bm
funs = sorted(list(funs))
args = sorted(list(args))
#max_name = max(len(i) for i in funs)
for a in args:
tag = "/".join(str(i) for i in [*a,])
print(tag)
base_time = data["/".join([funs[0], tag])]["cpu_time"]
for f in funs:
name = "/".join([f, tag])
perf = 100.0
if f != funs[0]:
perf = data[name]["cpu_time"] / base_time * 100
print(" {:20s}{:>10.2f}{}{:>10.2f}%".format(f, data[name]["cpu_time"], data[name]["time_unit"], perf))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment