File: benchmark.py

package info (click to toggle)
upb 0.0.0~git200730-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,684 kB
  • sloc: ansic: 16,828; cpp: 5,098; python: 360; pascal: 160; ruby: 21; sh: 19; makefile: 5
file content (32 lines) | stat: -rwxr-xr-x 994 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3

import json
import subprocess
import re

def Run(cmd):
  subprocess.check_call(cmd, shell=True)

def RunAgainstBranch(branch, outfile, runs=12):
  tmpfile = "/tmp/bench-output.json"
  Run("rm -rf {}".format(tmpfile))
  Run("git checkout {}".format(branch))
  Run("bazel build -c opt :benchmark")

  Run("./bazel-bin/benchmark --benchmark_out_format=json --benchmark_out={} --benchmark_repetitions={}".format(tmpfile, runs))

  with open(tmpfile) as f:
    bench_json = json.load(f)

  with open(outfile, "w") as f:
    for run in bench_json["benchmarks"]:
      name = re.sub(r'^BM_', 'Benchmark', run["name"])
      if name.endswith("_mean") or name.endswith("_median") or name.endswith("_stddev"):
        continue
      values = (name, run["iterations"], run["cpu_time"])
      print("{} {} {} ns/op".format(*values), file=f)

RunAgainstBranch("master", "/tmp/old.txt")
RunAgainstBranch("decoder", "/tmp/new.txt")

Run("~/go/bin/benchstat /tmp/old.txt /tmp/new.txt")