Skip to content

Instantly share code, notes, and snippets.

@aprice
Created September 16, 2016 19:28
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 aprice/d757dcb7e8348beed3cbdda544ab98d5 to your computer and use it in GitHub Desktop.
Save aprice/d757dcb7e8348beed3cbdda544ab98d5 to your computer and use it in GitHub Desktop.
Compare golang benchmarks between working copy and pristine
#!/bin/bash
# Usage: benchwc.sh "path/to/package" "-build flags"
# e.g. benchwc.sh ./mypkg "-cpu=1,2,4 -tags=debug -benchtime=2s"
DIR=${1:-.}
BFLAGS=$2
git stash save || exit 1
cd $DIR && go test -run=^$ -bench=. -benchmem $BFLAGS | tee old.out
git stash pop || exit 1
cd $DIR && go test -run=^$ -bench=. -benchmem $BFLAGS | tee new.out
benchcmp old.out new.out | tee comparison.out
@aprice
Copy link
Author

aprice commented Sep 16, 2016

Note this requires benchcmp to be installed:
go get golang.org/x/tools/cmd/benchcmp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment