[go-nuts] Re: Trying to understand Go benchmarking
Sorry for creating confusion, my reading mistake. I read the inner-loop as: if err := bdb.Get(key, ); err == nil && val.Value() != nil { totalFound++ } else if err != nil { totalErrored++ } else { totalNotFound++ } Which it obviously is not... :/ This day doesn't seem promising after this obvious oversight :D + Egon On Thursday, 10 August 2017 10:10:07 UTC+3, peterGo wrote: > > Egon, > > Obviously I ran the race detector. No races were detected. Therefore, > since it wasn't germane, I omitted it from the posted results. > > Here's my results. > > $ go test -run=! -bench=. -v -cpu=4 -race total_test.go > goos: linux > goarch: amd64 > BenchmarkTotal/Count-4 500024.4 ns/op > --- BENCH: BenchmarkTotal/Count-4 > total_test.go:16: count 1 > total_test.go:16: count 0 > total_test.go:16: count 0 > total_test.go:16: count 0 > total_test.go:16: count 100 > total_test.go:16: count 0 > total_test.go:16: count 0 > total_test.go:16: count 0 > total_test.go:16: count 3060 > total_test.go:16: count 3980 > ... [output truncated] > --- BENCH: BenchmarkTotal > total_test.go:20: total 51010101 > PASS > ok command-line-arguments2.258s > > Please post you results that show a race. > > Peter > > On Thursday, August 10, 2017 at 3:01:45 AM UTC-4, Egon wrote: >> >> 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-1282000 >>> 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 (2000), 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, ); err == nil && val.Value() != nil { >>> found++ >>> } else if err != nil { >>> errored++ >>> } else { >>> notFound++ >>> } >>> } >>> atomic.AddUint64(, found) >>> atomic.AddUint64(, errored) >>> atomic.AddUint64(, 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.
[go-nuts] Re: Trying to understand Go benchmarking
Egon, Obviously I ran the race detector. No races were detected. Therefore, since it wasn't germane, I omitted it from the posted results. Here's my results. $ go test -run=! -bench=. -v -cpu=4 -race total_test.go goos: linux goarch: amd64 BenchmarkTotal/Count-4 500024.4 ns/op --- BENCH: BenchmarkTotal/Count-4 total_test.go:16: count 1 total_test.go:16: count 0 total_test.go:16: count 0 total_test.go:16: count 0 total_test.go:16: count 100 total_test.go:16: count 0 total_test.go:16: count 0 total_test.go:16: count 0 total_test.go:16: count 3060 total_test.go:16: count 3980 ... [output truncated] --- BENCH: BenchmarkTotal total_test.go:20: total 51010101 PASS ok command-line-arguments2.258s Please post you results that show a race. Peter On Thursday, August 10, 2017 at 3:01:45 AM UTC-4, Egon wrote: > > 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-1282000 >> 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 (2000), 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, ); err == nil && val.Value() != nil { >> found++ >> } else if err != nil { >> errored++ >> } else { >> notFound++ >> } >> } >> atomic.AddUint64(, found) >> atomic.AddUint64(, errored) >> atomic.AddUint64(, 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.
[go-nuts] Re: Trying to understand Go benchmarking
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-1282000 > 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 (2000), 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, ); err == nil && val.Value() != nil { > found++ > } else if err != nil { > errored++ > } else { > notFound++ > } > } > atomic.AddUint64(, found) > atomic.AddUint64(, errored) > atomic.AddUint64(, 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.
[go-nuts] Re: Trying to understand Go benchmarking
Package testing https://golang.org/pkg/testing/ Benchmarks The benchmark function must run the target code b.N times. During benchmark execution, b.N is adjusted until the benchmark function lasts long enough to be timed reliably. The first thing to do is to reduce the program to the simplest program that exhibits the behavior. For example, package main import ( "sync/atomic" "testing" ) func BenchmarkTotal(b *testing.B) { var total uint64 b.Run("Count", func(b *testing.B) { b.RunParallel(func(pb *testing.PB) { var count uint64 for pb.Next() { count++ } b.Logf("count %d", count) atomic.AddUint64(, count) }) }) b.Logf("total %d", total) } $ go test -run=! -bench=. -v -cpu=1 total_test.go goos: linux goarch: amd64 BenchmarkTotal/Count 10 2.17 ns/op --- BENCH: BenchmarkTotal/Count total_test.go:16: count 1 total_test.go:16: count 100 total_test.go:16: count 1 total_test.go:16: count 100 total_test.go:16: count 1 total_test.go:16: count 10 --- BENCH: BenchmarkTotal total_test.go:20: total 1101010101 PASS ok command-line-arguments2.391s 10 is the final total and 1101010101 is the sum of all totals. Peter On Wednesday, August 9, 2017 at 11:43:34 PM UTC-4, 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-1282000 > 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 (2000), 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, ); err == nil && val.Value() != nil { > found++ > } else if err != nil { > errored++ > } else { > notFound++ > } > } > atomic.AddUint64(, found) > atomic.AddUint64(, errored) > atomic.AddUint64(, 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.