summaryrefslogtreecommitdiff
path: root/misc/benchcmp
diff options
context:
space:
mode:
authorJeff R. Allen <jra@nella.org>2012-11-03 02:13:51 +0800
committerJeff R. Allen <jra@nella.org>2012-11-03 02:13:51 +0800
commitf89b74f717add59996aeaabe4bf91b3e863ba69a (patch)
tree2ece92b61d24cb30e490a3464ab06dfcb164794a /misc/benchcmp
parentfd0abc779096b93772e5be0116fdc3e3ebac1aa3 (diff)
downloadgo-f89b74f717add59996aeaabe4bf91b3e863ba69a.tar.gz
misc/benchcmp: show memory statistics, when available
R=minux.ma, dave, extraterrestrial.neighbour, rsc CC=golang-dev http://codereview.appspot.com/6587069 Committer: Shenghou Ma <minux.ma@gmail.com>
Diffstat (limited to 'misc/benchcmp')
-rwxr-xr-xmisc/benchcmp36
1 files changed, 34 insertions, 2 deletions
diff --git a/misc/benchcmp b/misc/benchcmp
index 015e7d2b2..b98ee2b2f 100755
--- a/misc/benchcmp
+++ b/misc/benchcmp
@@ -7,8 +7,13 @@ case "$1" in
-*)
echo 'usage: benchcmp old.txt new.txt' >&2
echo >&2
- echo 'Each input file should be go test -test.run=NONE -test.bench=. > [old,new].txt' >&2
+ echo 'Each input file should be from:' >&2
+ echo ' go test -test.run=NONE -test.bench=. > [old,new].txt' >&2
+ echo >&2
echo 'Benchcmp compares the first and last for each benchmark.' >&2
+ echo >&2
+ echo 'If -test.benchmem=true is added to the "go test" command' >&2
+ echo 'benchcmp will also compare memory allocations.' >&2
exit 2
esac
@@ -27,10 +32,21 @@ $1 ~ /Benchmark/ && $4 == "ns/op" {
new[$1] = $3
if($6 == "MB/s")
newmb[$1] = $5
+
+ # allocs/op might be at $8 or $10 depending on if
+ # SetBytes was used or not.
+ if($8 == "allocs/op")
+ newalloc[$1] = $7
+ if($10 == "allocs/op")
+ newalloc[$1] = $9
} else {
old[$1] = $3
- if($6 = "MB/s")
+ if($6 == "MB/s")
oldmb[$1] = $5
+ if($8 == "allocs/op")
+ oldalloc[$1] = $7
+ if($10 == "allocs/op")
+ oldalloc[$1] = $9
}
}
@@ -62,5 +78,21 @@ END {
sprintf("%.2f", newmb[what]),
sprintf("%.2f", newmb[what]/oldmb[what]))
}
+
+ # print allocs
+ anyalloc = 0
+ for(i=0; i<n; i++) {
+ what = name[i]
+ if(!(what in newalloc))
+ continue
+ if(anyalloc++ == 0)
+ printf("\n%-*s %12s %12s %7s\n", len, "benchmark", "old allocs", "new allocs", "delta")
+ if(oldalloc[what] == 0)
+ delta="n/a"
+ else
+ delta=sprintf("%.2f", 100*newalloc[what]/oldalloc[what]-100)
+ printf("%-*s %12d %12d %6s%%\n", len, what,
+ oldalloc[what], newalloc[what], delta)
+ }
}
' "$@"