aboutsummaryrefslogtreecommitdiff
path: root/rwtransaction_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'rwtransaction_test.go')
-rw-r--r--rwtransaction_test.go39
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
+ })
+ })
+}