Skip to content

Instantly share code, notes, and snippets.

@0del
Created July 28, 2022 09:05
Show Gist options
  • Save 0del/0dcc0f3d61da05d6fc39655baa629451 to your computer and use it in GitHub Desktop.
Save 0del/0dcc0f3d61da05d6fc39655baa629451 to your computer and use it in GitHub Desktop.
Generate benchmark files in a Git repository.
#!/bin/bash
#
# Generate benchmark files in a Git repository.
#
# Usage: TIMES=1 go-bench [prefix]
#
# Number of times to run the benchmark; useful for benchstat.
TIMES=${TIMES:-1}
# Prefix of the output file; useful for placing in a subdirectory.
PREFIX=${1:-benchmark.}
# Assume we're in a git repository, so we can remember which commit
# was the result of a benchmark.
REF=$(git rev-parse --short HEAD)
# Generate a file with a timestamp so that we can easily sort the
# benchmarks during comparison.
FILE="${PREFIX}$(date '+%Y%m%d%H%M')-${REF}.txt"
mkdir -p ${PREFIX}
function do_bench {
for i in $(seq 1 $TIMES); do
go test -v -run=^$ -bench=. -benchmem ./...
done
}
do_bench > ${FILE}
@0del
Copy link
Author

0del commented Jul 28, 2022

Run benchmark

Out will save in out folder

TIMES=5 ./go-bench.sh out/  

Compress all output

find out -type f | tail -2 | xargs benchstat

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