Skip to content

Commit dc4d281

Browse files
committed
Update testing-and-benchmarking for new benchmark Loop of Go 1.24
1 parent a0afe45 commit dc4d281

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

examples/testing-and-benchmarking/main_test.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestIntMinTableDriven(t *testing.T) {
5454
}
5555

5656
for _, tt := range tests {
57-
// t.Run enables running "subtests", one for each
57+
// `t.Run` enables running "subtests", one for each
5858
// table entry. These are shown separately
5959
// when executing `go test -v`.
6060
testname := fmt.Sprintf("%d,%d", tt.a, tt.b)
@@ -68,13 +68,14 @@ func TestIntMinTableDriven(t *testing.T) {
6868
}
6969

7070
// Benchmark tests typically go in `_test.go` files and are
71-
// named beginning with `Benchmark`. The `testing` runner
72-
// executes each benchmark function several times, increasing
73-
// `b.N` on each run until it collects a precise measurement.
71+
// named beginning with `Benchmark`.
72+
// Any code that's required for the benchmark to run but should
73+
// not be measured goes before this loop.
7474
func BenchmarkIntMin(b *testing.B) {
75-
// Typically the benchmark runs a function we're
76-
// benchmarking in a loop `b.N` times.
77-
for i := 0; i < b.N; i++ {
75+
for b.Loop() {
76+
// The benchmark runner will automatically execute this loop
77+
// body many times to determine a reasonable estimate of the
78+
// run-time of a single iteration.
7879
IntMin(1, 2)
7980
}
8081
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
565e50f23b399cdbca4aedeb8b62b9f6ad097443
2+
osZckbKSkse

examples/testing-and-benchmarking/testing.hash

-2
This file was deleted.

0 commit comments

Comments
 (0)