diff options
author | Jorropo <jorropo.pgm@gmail.com> | 2024-05-02 18:38:35 +0200 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2024-05-02 18:41:57 +0000 |
commit | 865cf5c5f626d2546b3023217f0a0fb2e5ad9304 (patch) | |
tree | 9cc43cd56dc66481bfdec7fc3a4c89a716e7f0db /src | |
parent | 660a071906a3f010a947457521b7671041b5f737 (diff) | |
download | go-865cf5c5f626d2546b3023217f0a0fb2e5ad9304.tar.gz go-865cf5c5f626d2546b3023217f0a0fb2e5ad9304.zip |
testing: improve the documentation around b.N
Fixes #67137
- Make it clear the benchmark function is called multiple times.
- Demonstrate range over int.
Change-Id: I7e993d938b0351012cdd4aed8528951e0ad406ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/582835
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/testing/testing.go | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index 2289c6717f..60f0c23137 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -72,14 +72,15 @@ // A sample benchmark function looks like this: // // func BenchmarkRandInt(b *testing.B) { -// for i := 0; i < b.N; i++ { +// for range b.N { // rand.Int() // } // } // // The benchmark function must run the target code b.N times. -// During benchmark execution, b.N is adjusted until the benchmark function lasts -// long enough to be timed reliably. The output +// It is called multiple times with b.N adjusted until the +// benchmark function lasts long enough to be timed reliably. +// The output // // BenchmarkRandInt-8 68453040 17.8 ns/op // @@ -91,7 +92,7 @@ // func BenchmarkBigLen(b *testing.B) { // big := NewBig() // b.ResetTimer() -// for i := 0; i < b.N; i++ { +// for range b.N { // big.Len() // } // } |