|
79 | 79 | // name time/op
|
80 | 80 | // GobEncode 13.6ms ± 1%
|
81 | 81 | // JSONEncode 32.1ms ± 1%
|
82 |
| -// $ |
83 | 82 | //
|
84 | 83 | // If run with two input files, benchstat summarizes and compares:
|
85 | 84 | //
|
86 | 85 | // $ benchstat old.txt new.txt
|
87 | 86 | // name old time/op new time/op delta
|
88 | 87 | // GobEncode 13.6ms ± 1% 11.8ms ± 1% -13.31% (p=0.016 n=4+5)
|
89 | 88 | // JSONEncode 32.1ms ± 1% 31.8ms ± 1% ~ (p=0.286 n=4+5)
|
90 |
| -// $ |
91 | 89 | //
|
92 | 90 | // Note that the JSONEncode result is reported as
|
93 | 91 | // statistically insignificant instead of a -0.93% delta.
|
94 | 92 | //
|
| 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). |
95 | 125 | package main
|
96 | 126 |
|
97 | 127 | import (
|
|
0 commit comments