Note, you also have a race in your code.

Use `-race` to detect.

+ Egon

On Thursday, 10 August 2017 06:43:34 UTC+3, d...@dgraph.io wrote:
>
> Hi
>
> 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
> PASS
> 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.
>
> Code:
>
> ===
> func BenchmarkReadRandomBadger(b *testing.B) {
>         // store setup
>         bdb, err := getBadger()
> y.Check(err)
> 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 {
> found++
> } else if err != nil {
> errored++
> } else {
> notFound++
> }
> }
> 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