-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-bench.sh
executable file
·46 lines (38 loc) · 1.17 KB
/
run-bench.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
OUTPUT="${1}"
FLAGS="${@:2}"
if [ -z "${OUTPUT}" ]; then
OUTPUT=bench/$(git rev-parse --short HEAD)
fi
if [[ ! ("${FLAGS}" =~ -bench) ]]; then
FLAGS+=("-bench=.")
fi
if [[ ! ("${FLAGS}" =~ -timeout) ]]; then
FLAGS+=("-timeout=0")
fi
if [ ! -z "$(git status --porcelain)" ]; then
echo -e "WARNING: git tree is dirty\n"
if [ -e "${OUTPUT}.log" ]; then
echo "
Won't append to already existing file ${OUTPUT}.log with a dirty tree.
You may provide a different output as argument to this script"
exit 1
fi
fi
# Echo command (set -x) for a specific one: https://unix.stackexchange.com/a/177911/420855
# Get first error code of a pipe: https://unix.stackexchange.com/a/73180/420855
TMPOUTPUT=$(mktemp)
( set -x -o pipefail; go1.18 test ./... -v -run=TestXXX ${FLAGS[@]} | tee -a "${TMPOUTPUT}" )
if [ $? -ne 0 ]; then
exit
else
cat "${TMPOUTPUT}" >> "${OUTPUT}.log"
fi
if ! command -v benchstat &>/dev/null; then
echo "
benchstat is not installed. You can install it with
go install golang.org/x/perf/cmd/benchstat"
else
(set -x; benchstat -csv "${OUTPUT}.log" > "${OUTPUT}.csv")
echo "Stat analysis written to ${OUTPUT}.csv"
fi