August 2019
Beginner to intermediate
798 pages
17h 2m
English
Look at the Go code of the following benchmark function:
func BenchmarkFiboI(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = fibo1(i)
}
}
The BenchmarkFibo() function has a valid name and the correct signature. The bad news, however, is that this benchmark function is wrong, and you will not get any output from it after executing the go test command.
The reason for this is that as the b.N value grows in the way described earlier, the runtime of the benchmark function will also increase because of the for loop. This fact prevents BenchmarkFiboI() from converging to a stable number, which prevents the function from completing and therefore returning.
For analogous reasons, the next benchmark function is also ...
Read now
Unlock full access