Skip to content

Commit 339e355

Browse files
committed
cmd/benchstat: add example benchmarking workflow to package comment
1 parent 7c3f212 commit 339e355

File tree

2 files changed

+32
-87
lines changed

2 files changed

+32
-87
lines changed

cmd/benchstat/README.md

Lines changed: 0 additions & 85 deletions
This file was deleted.

cmd/benchstat/main.go

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,49 @@
7979
// name time/op
8080
// GobEncode 13.6ms ± 1%
8181
// JSONEncode 32.1ms ± 1%
82-
// $
8382
//
8483
// If run with two input files, benchstat summarizes and compares:
8584
//
8685
// $ benchstat old.txt new.txt
8786
// name old time/op new time/op delta
8887
// GobEncode 13.6ms ± 1% 11.8ms ± 1% -13.31% (p=0.016 n=4+5)
8988
// JSONEncode 32.1ms ± 1% 31.8ms ± 1% ~ (p=0.286 n=4+5)
90-
// $
9189
//
9290
// Note that the JSONEncode result is reported as
9391
// statistically insignificant instead of a -0.93% delta.
9492
//
93+
// An example benchmarking workflow in Unix shell language:
94+
//
95+
// oldBin=/tmp/benchmarkBinaryOld
96+
// newBin=/tmp/benchmarkBinaryNew
97+
// old=/tmp/benchmarkReportOld
98+
// new=/tmp/benchmarkReportNew
99+
// result=/tmp/benchstatReport
100+
//
101+
// # Create first test executable.
102+
// go test -c -o "$oldBin" -bench .
103+
//
104+
// # Apply code patch now
105+
// git checkout fixes
106+
//
107+
// # Create the other test executable.
108+
// go test -c -o "$newBin" -bench .
109+
//
110+
// # Test and benchmark.
111+
// for i in 0 1 2 3 4 5 6 7 8 9 10 11 12 13; do
112+
// printf 'Tests %s starting.\n' "$i"
113+
// "$oldBin" -test.bench . >> "$old"
114+
// "$newBin" -test.bench . >> "$new"
115+
// done
116+
//
117+
// # Create final report with benchstat.
118+
// benchstat "$old" "$new" > "$result"
119+
//
120+
// Possible variations include disabling tests (done with the command
121+
// line arguments "-run -"), running three instead of two benchmark
122+
// executables in the loop or increasing niceness or, even better,
123+
// running the binaries under a real time scheduling policy (see
124+
// sched_setscheduler and SCHED_FIFO).
95125
package main
96126

97127
import (

0 commit comments

Comments
 (0)