summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2022-08-04 21:58:31 +0700
committerShulhan <ms@kilabit.info>2022-08-05 20:52:47 +0700
commit93ee0a047861c8afa582c719f2a4be1932e2e1ba (patch)
tree1e151bc845a119eb8675d9283b27c6138011173e
parent1060faab647b444ffbd3cdc47c286c7ba56b72fb (diff)
downloadpakakeh.go-93ee0a047861c8afa582c719f2a4be1932e2e1ba.tar.xz
_bin: add script to run Go benchmark
The go-bench.sh accept two arguments: the method or function to benchmark, default to "."; and benchmark number, default to current timestamp YYYYmmDD-HHMM.
-rwxr-xr-x_bin/go-bench.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/_bin/go-bench.sh b/_bin/go-bench.sh
new file mode 100755
index 00000000..6a1721f6
--- /dev/null
+++ b/_bin/go-bench.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+## Script to run Go benchmark in the current package.
+##
+## Arg 1: the method or function to benchmark, default to ".".
+## Arg 2: the benchmark number, default to "YYYYmmDD-HHMM".
+##
+## This script output three files:
+## - bench_$1_$2.cpu.prof
+## - bench_$1_$2.mem.prof
+## - bench_$1_$2.txt
+
+TIMESTAMP=$(date +%Y%m%d-%H%M)
+
+FN=${1:-.}
+NO=${2:-$TIMESTAMP}
+
+BENCH_OUT="bench_${FN}_${NO}.txt"
+CPU_PROF="bench_${FN}_${NO}_cpu.prof"
+MEM_PROF="bench_${FN}_${NO}_mem.prof"
+
+export GORACE=history_size=7
+export CGO_ENABLED=1
+go test -race -run=noop -benchmem -bench=${FN} \
+ -cpuprofile=${CPU_PROF} \
+ -memprofile=${MEM_PROF} \
+ -count=5 \
+ . \
+ |& tee $BENCH_OUT