I have a test that has some init that takes a few seconds like:
func Benchmark(b *testing.B) {
b.StopTimer()
//long init
b.StartTime()
for i := 0; i < b.N; i++ {
//func that takes around 50ms
}
}
and what I am seeing is that if -benchtime is at 1s then I get a ns/op time that is above 1 second, which is not correct?
However the higher I put -benchtime the more and more the ns/op approaches the correct 50ms time.
If I put the b.StopTimer()/b.StartTime() around the func in the iteration loop, it always gives the correct ns/op time. However
as far as I understand I can't use that kind of thing for b.RunParallel().
So what is the correct usage and expected behavior and what to do with b.RunParallel()?