I am trying to benchmark a key-value store written in Go. I have the code 
as shown below. There are a few lines that are specific to the store 
itself, other than that it is all related to benchmarking. I am trying to 
find the no. of keys that have valid values versus the no. of keys that 
dont have values.

Running the code below as 

go test -v --bench BenchmarkReadRandomBadger  --timeout 10m --benchtime 3m 

results in this output

BenchmarkReadRandomBadger/read-random-badger-128                20000000   
          11842 ns/op
--- BENCH: BenchmarkReadRandomBadger
        bench_test.go:101: badger 13277801 keys had valid values.
        bench_test.go:102: badger 7732300 keys had no values
        bench_test.go:103: badger 0 keys had errors
ok      github.com/dgraph-io/badger-bench       256.448s

Now, based on my understanding, the values above should add up to the 
number of iterations (20000000), but instead add up to 13277801+7732300 
= 21010101

Can somebody help me understand this discrepancy.


func BenchmarkReadRandomBadger(b *testing.B) {
        // store setup
        bdb, err := getBadger()
defer bdb.Close()

var totalFound uint64
var totalErr uint64
var totalNotFound uint64
b.Run("read-random-badger", func(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var found, errored, notFound uint64
for pb.Next() {
key := newKey()
var val badger.KVItem
                                // get value from store
if err := bdb.Get(key, &val); err == nil && val.Value() != nil {
} else if err != nil {
} else {
atomic.AddUint64(&totalFound, found)
atomic.AddUint64(&totalErr, errored)
atomic.AddUint64(&totalNotFound, notFound)
b.Logf("badger %d keys had valid values.", totalFound)
b.Logf("badger %d keys had no values", totalNotFound)
b.Logf("badger %d keys had errors", totalErr)

You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to