From 690eb8a1acaf84328389f77853d87cf6cbbaebd6 Mon Sep 17 00:00:00 2001
From: jidicula
Date: Wed, 1 Dec 2021 20:16:16 -0500
Subject: [PATCH] fix: Address PR comments
- Clarify meaning of `b.N`.
- Nix verbose flag in run example.
---
examples/testing/main_test.go | 9 ++++---
examples/testing/main_test.sh | 17 +------------
examples/testing/testing.hash | 4 ++--
public/testing | 45 +++++++++++++++++------------------
4 files changed, 31 insertions(+), 44 deletions(-)
diff --git a/examples/testing/main_test.go b/examples/testing/main_test.go
index 85fc243..c085951 100644
--- a/examples/testing/main_test.go
+++ b/examples/testing/main_test.go
@@ -67,10 +67,13 @@ func TestIntMinTableDriven(t *testing.T) {
}
}
-// Benchmark tests typically go in `_test.go` files and begin with `Benchmark`.
-// Each benchmark function is run several times, with `b.N` increasing on each
-// run until the `testing` runner deems the benchmark to be accurate.
+// Benchmark tests typically go in `_test.go` files and are
+// named beginning with `Benchmark`. The `testing` runner
+// executes each benchmark function several times, increasing
+// `b.N` on each run until it collects a precise measurement.
func BenchmarkIntMin(b *testing.B) {
+ // To measure a benchmark, the `testing` runner calls the
+ // function in a loop `b.N` times.
for i := 0; i < b.N; i++ {
IntMin(1, 2)
}
diff --git a/examples/testing/main_test.sh b/examples/testing/main_test.sh
index b6ae704..b04fdb2 100644
--- a/examples/testing/main_test.sh
+++ b/examples/testing/main_test.sh
@@ -20,25 +20,10 @@ ok examples/testing 0.023s
# Run all benchmarks in the current project in verbose
# mode. All tests are run prior to benchmarks. The `bench`
# flag receives a regex for benchmark function names.
-$ go test -v -bench=.
-=== RUN TestIntMinBasic
---- PASS: TestIntMinBasic (0.00s)
-=== RUN TestIntMinTableDriven
-=== RUN TestIntMinTableDriven/0,1
-=== RUN TestIntMinTableDriven/1,0
-=== RUN TestIntMinTableDriven/2,-2
-=== RUN TestIntMinTableDriven/0,-1
-=== RUN TestIntMinTableDriven/-1,0
---- PASS: TestIntMinTableDriven (0.00s)
- --- PASS: TestIntMinTableDriven/0,1 (0.00s)
- --- PASS: TestIntMinTableDriven/1,0 (0.00s)
- --- PASS: TestIntMinTableDriven/2,-2 (0.00s)
- --- PASS: TestIntMinTableDriven/0,-1 (0.00s)
- --- PASS: TestIntMinTableDriven/-1,0 (0.00s)
+$ go test -bench=.
goos: darwin
goarch: arm64
pkg: examples/testing
-BenchmarkIntMin
BenchmarkIntMin-8 1000000000 0.3136 ns/op
PASS
ok examples/testing 0.351s
diff --git a/examples/testing/testing.hash b/examples/testing/testing.hash
index c3d896f..ccce2ec 100644
--- a/examples/testing/testing.hash
+++ b/examples/testing/testing.hash
@@ -1,2 +1,2 @@
-c3489e12554d4b865ae225bc8bad2d9e634fe429
-Ct1lKa6FttL
+d3b047089cf762a8aa9778a8365a29eb31363288
+HryvnW3zHYJ
diff --git a/public/testing b/public/testing
index 7ce6b1b..cf3c2a1 100644
--- a/public/testing
+++ b/public/testing
@@ -47,7 +47,7 @@ typically lives in the same package as the code it tests.
- 
+ 
package main
@@ -184,15 +184,29 @@ when executing go test -v .
|
- Benchmark tests typically go in _test.go files and begin with Benchmark .
-Each benchmark function is run several times, with b.N increasing on each
-run until the testing runner deems the benchmark to be accurate.
+ Benchmark tests typically go in _test.go files and are
+named beginning with Benchmark . The testing runner
+executes each benchmark function several times, increasing
+b.N on each run until it collects a precise measurement.
+
+ |
+
+
+
+func BenchmarkIntMin(b *testing.B) {
+
+ |
+
+
+
+
+ To measure a benchmark, the testing runner calls the
+function in a loop b.N times.
|
-func BenchmarkIntMin(b *testing.B) {
for i := 0; i < b.N; i++ {
IntMin(1, 2)
}
@@ -243,25 +257,10 @@ flag receives a regex for benchmark function names.
-$ go test -v -bench=.
-=== RUN TestIntMinBasic
---- PASS: TestIntMinBasic (0.00s)
-=== RUN TestIntMinTableDriven
-=== RUN TestIntMinTableDriven/0,1
-=== RUN TestIntMinTableDriven/1,0
-=== RUN TestIntMinTableDriven/2,-2
-=== RUN TestIntMinTableDriven/0,-1
-=== RUN TestIntMinTableDriven/-1,0
---- PASS: TestIntMinTableDriven (0.00s)
- --- PASS: TestIntMinTableDriven/0,1 (0.00s)
- --- PASS: TestIntMinTableDriven/1,0 (0.00s)
- --- PASS: TestIntMinTableDriven/2,-2 (0.00s)
- --- PASS: TestIntMinTableDriven/0,-1 (0.00s)
- --- PASS: TestIntMinTableDriven/-1,0 (0.00s)
-goos: darwin
+$ go test -bench=.
+goos: darwin
goarch: arm64
pkg: examples/testing
-BenchmarkIntMin
BenchmarkIntMin-8 1000000000 0.3136 ns/op
PASS
ok examples/testing 0.351s
@@ -283,7 +282,7 @@ flag receives a regex for benchmark function names.
| |