diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-04 13:02:17 -0700 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-03-04 13:23:46 -0700 |
commit | 64fcacedfa3e59e9dbb0cc0d2b3de71cae3290df (patch) | |
tree | 511db104025c34c4434c50e4367395be2bc806ba /rwtransaction_test.go | |
parent | Ignore multiple transaction commit/rollback/close. (diff) | |
download | dedo-64fcacedfa3e59e9dbb0cc0d2b3de71cae3290df.tar.gz dedo-64fcacedfa3e59e9dbb0cc0d2b3de71cae3290df.tar.xz |
Add benchmarks.
Diffstat (limited to 'rwtransaction_test.go')
-rw-r--r-- | rwtransaction_test.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/rwtransaction_test.go b/rwtransaction_test.go index 1635b45..e45ec10 100644 --- a/rwtransaction_test.go +++ b/rwtransaction_test.go @@ -1,6 +1,8 @@ package bolt import ( + "math/rand" + "strconv" "strings" "testing" @@ -140,3 +142,40 @@ func TestRWTransactionDeleteBucketNotFound(t *testing.T) { assert.Equal(t, err, ErrBucketNotFound) }) } + +// Benchmark the performance of bulk put transactions in random order. +func BenchmarkRWTransactionPutRandom(b *testing.B) { + indexes := rand.Perm(b.N) + value := []byte(strings.Repeat("0", 64)) + withOpenDB(func(db *DB, path string) { + db.CreateBucket("widgets") + var txn *RWTransaction + var bucket *Bucket + for i := 0; i < b.N; i++ { + if i%1000 == 0 { + if txn != nil { + txn.Commit() + } + txn, _ = db.RWTransaction() + bucket = txn.Bucket("widgets") + } + bucket.Put([]byte(strconv.Itoa(indexes[i])), value) + } + txn.Commit() + }) +} + +// Benchmark the performance of bulk put transactions in sequential order. +func BenchmarkRWTransactionPutSequential(b *testing.B) { + value := []byte(strings.Repeat("0", 64)) + withOpenDB(func(db *DB, path string) { + db.CreateBucket("widgets") + db.Do(func(txn *RWTransaction) error { + bucket := txn.Bucket("widgets") + for i := 0; i < b.N; i++ { + bucket.Put([]byte(strconv.Itoa(i)), value) + } + return nil + }) + }) +} |