summaryrefslogtreecommitdiff
path: root/misc/benchcmp
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-11-15 12:49:22 -0500
committerRuss Cox <rsc@golang.org>2011-11-15 12:49:22 -0500
commit2d37fa1cba7cfe70dbfbf927b820aa22b455733b (patch)
tree6c8fea9eec8590300bd76b9ca9512561bdad44e8 /misc/benchcmp
parenta1ce7c2d1d568317e735c8aa8e6b1ba336d4bfaf (diff)
downloadgo-2d37fa1cba7cfe70dbfbf927b820aa22b455733b.tar.gz
misc/benchcmp: benchmark comparison script
I've been using this since April and posted it on the mailing list, but it seems worth having in the repository. Not sure about the location. R=golang-dev, r, r CC=golang-dev http://codereview.appspot.com/5371100
Diffstat (limited to 'misc/benchcmp')
-rwxr-xr-xmisc/benchcmp66
1 files changed, 66 insertions, 0 deletions
diff --git a/misc/benchcmp b/misc/benchcmp
new file mode 100755
index 000000000..110c3429e
--- /dev/null
+++ b/misc/benchcmp
@@ -0,0 +1,66 @@
+#!/bin/sh
+# Copyright 2011 The Go Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style
+# license that can be found in the LICENSE file.
+
+case "$1" in
+-*)
+ echo 'usage: benchcmp old.txt new.txt' >&2
+ echo >&2
+ echo 'Each input file should be gotest -bench output.' >&2
+ echo 'Benchcmp compares the first and last for each benchmark.' >&2
+ exit 2
+esac
+
+awk '
+BEGIN {
+ n = 0
+}
+
+$1 ~ /^Benchmark/ && $4 == "ns/op" {
+ if(old[$1]) {
+ if(!saw[$1]++) {
+ name[n++] = $1
+ if(length($1) > len)
+ len = length($1)
+ }
+ new[$1] = $3
+ if($6 == "MB/s")
+ newmb[$1] = $5
+ } else {
+ old[$1] = $3
+ if($6 = "MB/s")
+ oldmb[$1] = $5
+ }
+}
+
+END {
+ if(n == 0) {
+ print "benchcmp: no repeated benchmarks" >"/dev/stderr"
+ exit 1
+ }
+
+ printf("%-*s %12s %12s %7s\n", len, "benchmark", "old ns/op", "new ns/op", "delta")
+
+ # print ns/op
+ for(i=0; i<n; i++) {
+ what = name[i]
+ printf("%-*s %12d %12d %6s%%\n", len, what, old[what], new[what],
+ sprintf("%+.2f", 100*new[what]/old[what]-100))
+ }
+
+ # print mb/s
+ anymb = 0
+ for(i=0; i<n; i++) {
+ what = name[i]
+ if(!(what in newmb))
+ continue
+ if(anymb++ == 0)
+ printf("\n%-*s %12s %12s %7s\n", len, "benchmark", "old MB/s", "new MB/s", "speedup")
+ printf("%-*s %12s %12s %6sx\n", len, what,
+ sprintf("%.2f", oldmb[what]),
+ sprintf("%.2f", newmb[what]),
+ sprintf("%.2f", newmb[what]/oldmb[what]))
+ }
+}
+' "$@"