aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-04-04 13:08:40 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-04-04 13:08:40 -0600
commitfeb84e39be469e2db15c1bd87f31cac08872501d (patch)
treebf14e2cf460c8b8ababfb07efd2c86ee2ded23db
parentMerge pull request #119 from benbjohnson/tx-rename (diff)
downloaddedo-feb84e39be469e2db15c1bd87f31cac08872501d.tar.gz
dedo-feb84e39be469e2db15c1bd87f31cac08872501d.tar.xz
Update cursor benchmark.
-rw-r--r--tx_test.go34
1 files changed, 19 insertions, 15 deletions
diff --git a/tx_test.go b/tx_test.go
index 3372dff..5179581 100644
--- a/tx_test.go
+++ b/tx_test.go
@@ -514,33 +514,37 @@ func TestTx_OnCommit_Rollback(t *testing.T) {
// Benchmark the performance iterating over a cursor.
func BenchmarkTxCursor(b *testing.B) {
- indexes := rand.Perm(b.N)
- value := []byte(strings.Repeat("0", 64))
+ var total = 50000
+ indexes := rand.Perm(total)
+ value := []byte(strings.Repeat("0", 100))
+ warn("X", b.N)
withOpenDB(func(db *DB, path string) {
// Write data to bucket.
db.Update(func(tx *Tx) error {
tx.CreateBucket("widgets")
bucket := tx.Bucket("widgets")
- for i := 0; i < b.N; i++ {
- bucket.Put([]byte(strconv.Itoa(indexes[i])), value)
+ for i := 0; i < total; i++ {
+ bucket.Put([]byte(fmt.Sprintf("%016d", indexes[i])), value)
}
return nil
})
b.ResetTimer()
// Iterate over bucket using cursor.
- db.View(func(tx *Tx) error {
- count := 0
- c := tx.Bucket("widgets").Cursor()
- for k, _ := c.First(); k != nil; k, _ = c.Next() {
- count++
- }
- if count != b.N {
- b.Fatalf("wrong count: %d; expected: %d", count, b.N)
- }
- return nil
- })
+ for i := 0; i < b.N; i++ {
+ db.View(func(tx *Tx) error {
+ count := 0
+ c := tx.Bucket("widgets").Cursor()
+ for k, _ := c.First(); k != nil; k, _ = c.Next() {
+ count++
+ }
+ if count != total {
+ b.Fatalf("wrong count: %d; expected: %d", count, total)
+ }
+ return nil
+ })
+ }
})
}