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 /db_test.go | |
parent | Ignore multiple transaction commit/rollback/close. (diff) | |
download | dedo-64fcacedfa3e59e9dbb0cc0d2b3de71cae3290df.tar.gz dedo-64fcacedfa3e59e9dbb0cc0d2b3de71cae3290df.tar.xz |
Add benchmarks.
Diffstat (limited to 'db_test.go')
-rw-r--r-- | db_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -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-") |