Go code
func BenchmarkAdd(b *testing.B) {
for i := 0; i < b.N; i++ {
Add(2, 3)
}
}Line-by-line explanation
- The name begins with Benchmark.
- B manages measurement.
- Go chooses b.N for reliable timing.
- The operation runs repeatedly.
Expected output
BenchmarkAdd-8 1000000000 0.3 ns/opNumbers vary by computer and Go version.
Run benchmarks with go test -bench=.. Measure realistic work and compare several runs.