The previous recipe walks through the testing part of the testing package, and in this recipe, the basics of the benchmarking will be covered.
Benchmarking the code
How to do it...
- Open the console and create the folder chapter11/recipe03.
- Navigate to the directory.
- Create the file sample_test.go with the following content:
package main
import (
"log"
"testing"
)
func BenchmarkSampleOne(b *testing.B) {
logger := log.New(devNull{}, "test", log.Llongfile)
b.ResetTimer()
b.StartTimer()
for i := 0; i < b.N; i++ {
logger.Println("This si awesome")
}
b.StopTimer()
...