|
| 1 | +#!/usr/bin/env python |
| 2 | +# Copyright (c) 2017 Jeremy Rubin |
| 3 | +# Distributed under the MIT software license, see the accompanying |
| 4 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 5 | +''' |
| 6 | + This creates a numeric diff of two benchmark files from the bench |
| 7 | + executable. The results computed are percent speedup, i.e., 100*((first |
| 8 | + file)/(second file) - 1). Negative is slower, positive is faster. |
| 9 | +''' |
| 10 | + |
| 11 | +import sys |
| 12 | +try: |
| 13 | + with open(sys.argv[1], "r") as orig: |
| 14 | + with open(sys.argv[2], "r") as new: |
| 15 | + o = orig.readlines() |
| 16 | + n = new.readlines() |
| 17 | + n.pop(0) |
| 18 | + labels = o.pop(0).strip().split(",") |
| 19 | + names = [labels.pop(0)] |
| 20 | + diffs = [labels] |
| 21 | + for (a, b) in zip(o,n): |
| 22 | + a_= a.split(",") |
| 23 | + b_ = b.split(",") |
| 24 | + a_.pop(0) |
| 25 | + names.append(b_.pop(0)) |
| 26 | + a_nums = map(float, a_) |
| 27 | + b_nums = map(float, b_) |
| 28 | + diff = map(lambda (x,y):"%+.2f%%"%(100*((x/y) -1)), zip(a_nums, b_nums)) |
| 29 | + diffs.append(diff) |
| 30 | + longname = max(map(len, names)) |
| 31 | + names = map(lambda s: s + ","+ " "*(longname - len(s)), names) |
| 32 | + |
| 33 | + |
| 34 | + for (name, diff) in zip(names, diffs): |
| 35 | + print name, ", ".join(diff) |
| 36 | + |
| 37 | +except Exception as e: |
| 38 | + print e |
| 39 | + print "Usage: ./benchdiff file1 file2" |
| 40 | + print "Returns a numeric diff of two benchmark files" |
| 41 | + |
| 42 | + |
0 commit comments