Debian Codegraph @

_benchmarks/bench.sh

raw
1 #!/usr/bin/env bash
2 set -e
3
4 declare -A PKGS=(
5 ["strconv"]="strconv"
6 ["net/http"]="net/http"
7 ["image/color"]="image/color"
8 ["std"]="std"
9 ["k8s"]="k8s.io/kubernetes/pkg/..."
10 )
11
12 MIN_CORES=32
13 MAX_CORES=32
14 INCR_CORES=2
15 MIN_GOGC=100
16 MAX_GOGC=100
17 SAMPLES=10
18 WIPE_CACHE=1
19 FORMAT=bench
20 BIN=$(realpath ./silent-staticcheck.sh)
21
22 runBenchmark() {
23 local pkg="$1"
24 local label="$2"
25 local gc="$3"
26 local cores="$4"
27 local wipe="$5"
28
29 if [ $wipe -ne 0 ]; then
30 rm -rf ~/.cache/staticcheck
31 fi
32
33 local out=$(GOGC=$gc GOMAXPROCS=$cores env time -f "%e %M" $BIN $pkg 2>&1)
34 local t=$(echo "$out" | cut -f1 -d" ")
35 local m=$(echo "$out" | cut -f2 -d" ")
36 local ns=$(printf "%s 1000000000 * p" $t | dc)
37 local b=$((m * 1024))
38
39 case $FORMAT in
40 bench)
41 printf "BenchmarkStaticcheck-%s-GOGC%d-wiped%d-%d 1 %.0f ns/op %.0f B/op\n" "$label" "$gc" "$wipe" "$cores" "$ns" "$b"
42 ;;
43 csv)
44 printf "%s,%d,%d,%d,%.0f,%.0f\n" "$label" "$gc" "$cores" "$wipe" "$ns" "$b"
45 ;;
46 esac
47 }
48
49 export GO111MODULE=off
50
51 if [ "$FORMAT" = "csv" ]; then
52 printf "packages,gogc,gomaxprocs,wipe-cache,time,memory\n"
53 fi
54
55 for label in "${!PKGS[@]}"; do
56 pkg=${PKGS[$label]}
57 for gc in $(seq $MIN_GOGC 10 $MAX_GOGC); do
58 for cores in $(seq $MIN_CORES $INCR_CORES $MAX_CORES); do
59 for i in $(seq 1 $SAMPLES); do
60 runBenchmark "$pkg" "$label" "$gc" "$cores" 1
61 runBenchmark "$pkg" "$label" "$gc" "$cores" 0
62 done
63 done
64 done
65 done