aboutsummaryrefslogtreecommitdiff
path: root/db_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'db_test.go')
-rw-r--r--db_test.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/db_test.go b/db_test.go
index 2b7975c..c8a8267 100644
--- a/db_test.go
+++ b/db_test.go
@@ -3,8 +3,10 @@ package bolt
import (
"io"
"io/ioutil"
+ "math/rand"
"os"
"strconv"
+ "strings"
"syscall"
"testing"
"time"
@@ -341,6 +343,29 @@ func TestDBString(t *testing.T) {
assert.Equal(t, db.GoString(), `bolt.DB{path:"/tmp/foo"}`)
}
+// Benchmark the performance of single put transactions in random order.
+func BenchmarkDBPutSequential(b *testing.B) {
+ value := []byte(strings.Repeat("0", 64))
+ withOpenDB(func(db *DB, path string) {
+ db.CreateBucket("widgets")
+ for i := 0; i < b.N; i++ {
+ db.Put("widgets", []byte(strconv.Itoa(i)), value)
+ }
+ })
+}
+
+// Benchmark the performance of single put transactions in random order.
+func BenchmarkDBPutRandom(b *testing.B) {
+ indexes := rand.Perm(b.N)
+ value := []byte(strings.Repeat("0", 64))
+ withOpenDB(func(db *DB, path string) {
+ db.CreateBucket("widgets")
+ for i := 0; i < b.N; i++ {
+ db.Put("widgets", []byte(strconv.Itoa(indexes[i])), value)
+ }
+ })
+}
+
// withDB executes a function with a database reference.
func withDB(fn func(*DB, string)) {
f, _ := ioutil.TempFile("", "bolt-")