When I run my benchmarks with go test -v -bench=. -benchmem
, I see the following results.
f1 10000 120860 ns/op 2433 B/op 28 allocs/op f2 10000 120288 ns/op 2288 B/op 26 allocs/op
Based on my understanding:
10000
is the number of iterations for i := 0; i < b.N; i++ {
. XXX ns/op
is approximate time it took for one iteration to completeBut even after reading the docs, I can not find out what B/op
and allocs/op
mean.
My guess is that allocs/op has something to do with garbage collection and memory allocation (the less the better).
Can anyone give a nice explanation of the meaning of these values. Also it would be nice to know why do the go up and main steps to reduce them (I realize this is test specific, but may be there are some universal hints that work in many cases)
A benchmark is a type of function that executes a code segment multiple times and compares each output against a standard, assessing the code's overall performance level.
allocs/op
means how many distinct memory allocations occurred per op (single iteration).
B/op
is how many bytes were allocated per op.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With