March 2020
Intermediate to advanced
406 pages
8h 39m
English
Benchmarks in Go use the axiom of starting with the word Benchmark (with a capital B) in the function call to denote that they are a benchmark and that they should use the benchmark functionality. To execute the benchmarks that you've defined for your code in your test package, you can use the -bench=. flag in your go test execution. This testing flag ensures all your benchmarking tests are run. An example of a benchmark is shown in the following code block:
package hello_test import ( "fmt" "testing" ) func BenchmarkHello(b *testing.B) { // Benchmark definition for i := 0; i < b.N; i++ { fmt.Sprintf("Hello High Performance Go") } }
In this (admittedly simple) benchmark, we are iterating over our fmt.Sprintf statement ...
Read now
Unlock full access