summaryrefslogtreecommitdiff
path: root/Benchmarking code in Golang.md
diff options
context:
space:
mode:
authorJasper Ras <jaspert.ras@gmail.com>2025-05-20 07:19:33 +0200
committerJasper Ras <jaspert.ras@gmail.com>2025-05-20 07:19:33 +0200
commita61d928b279c5c508aca3bfc7cb14d810c3d75de (patch)
tree6df664d4b58f1266e2782252547ed35e3c960b34 /Benchmarking code in Golang.md
parentd4bd3ad4a869c87fcfa4f83b42555a6c8e1bc746 (diff)
vault backup: 2025-05-20 07:19:33
Diffstat (limited to 'Benchmarking code in Golang.md')
-rw-r--r--Benchmarking code in Golang.md7
1 files changed, 3 insertions, 4 deletions
diff --git a/Benchmarking code in Golang.md b/Benchmarking code in Golang.md
index 22d180d..9bf9cfd 100644
--- a/Benchmarking code in Golang.md
+++ b/Benchmarking code in Golang.md
@@ -17,17 +17,16 @@ func main() {
Writing benchmarks. They look similar to tests:
```
-import testing
+import "testing"
func BenchmarkSome(b *testing.B) {
- for i := 0; i < b.N; i++ {
+ for b.Loop() {
Some()
}
}
```
-b.N is supplied by test driver and is dynamically changed depending on runtime.
-`go test -bench=<regex>`
+`go test -bench=<regex>` (thus `-bench=.` will run all tests)
This just benchmarks a function being called many times, comparative benchmarks can be written using a regular function being called from Benchmarks, something like so :
```