aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
authorMasahiro Furudate <178inaba.git@gmail.com>2020-02-21 03:29:43 +0900
committerIan Lance Taylor <iant@golang.org>2020-02-24 01:25:54 +0000
commit0f2a1574b02de3fec6937e65b1bdc21106bef15c (patch)
treee95af47a682fb4035e002b1bcfc3d0175e90da17 /src/testing
parent5bd145413a84be1afa74a82767384d9e224f7069 (diff)
downloadgo-0f2a1574b02de3fec6937e65b1bdc21106bef15c.tar.gz
go-0f2a1574b02de3fec6937e65b1bdc21106bef15c.zip
testing: change benchmark example function
Change to rand.Int, a function that the compiler cannot reliably eliminate. Fix output to actual benchmark values. Fixes #37341 Change-Id: Ifb5bf49b826ae0bdb4bf9de5a472ad0eaa54569c Reviewed-on: https://go-review.googlesource.com/c/go/+/220397 Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/testing.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 4b424e6abb..83cd72fff3 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -37,17 +37,17 @@
// https://golang.org/cmd/go/#hdr-Testing_flags
//
// A sample benchmark function looks like this:
-// func BenchmarkHello(b *testing.B) {
+// func BenchmarkRandInt(b *testing.B) {
// for i := 0; i < b.N; i++ {
-// fmt.Sprintf("hello")
+// 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
-// BenchmarkHello 10000000 282 ns/op
-// means that the loop ran 10000000 times at a speed of 282 ns per loop.
+// BenchmarkRandInt-8 68453040 17.8 ns/op
+// means that the loop ran 68453040 times at a speed of 17.8 ns per loop.
//
// If a benchmark needs some expensive setup before running, the timer
// may be reset: