diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-10 13:58:21 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-04-10 13:58:21 -0600 |
commit | e9c8f14d88c9a25c8bc4b568a9b74b9a65c642f5 (patch) | |
tree | 6f6785b4a0470b926ba9315fcc16b00ee9f859c4 | |
parent | Merge pull request #123 from Shopify/commit_in_binary (diff) | |
parent | make all benchmarks constant size and add multiple sizes (diff) | |
download | dedo-e9c8f14d88c9a25c8bc4b568a9b74b9a65c642f5.tar.gz dedo-e9c8f14d88c9a25c8bc4b568a9b74b9a65c642f5.tar.xz |
Merge pull request #122 from mkobetic/benchmark_tweaks
Make all benchmarks constant size and add multiple sizes
-rw-r--r-- | db_test.go | 34 | ||||
-rw-r--r-- | tx_test.go | 50 |
2 files changed, 35 insertions, 49 deletions
@@ -5,11 +5,8 @@ import ( "flag" "fmt" "io/ioutil" - "math/rand" "os" "regexp" - "strconv" - "strings" "testing" "time" "unsafe" @@ -322,37 +319,6 @@ 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.Update(func(tx *Tx) error { - return tx.CreateBucket("widgets") - }) - for i := 0; i < b.N; i++ { - db.Update(func(tx *Tx) error { - return tx.Bucket("widgets").Put([]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.Update(func(tx *Tx) error { - return tx.CreateBucket("widgets") - }) - for i := 0; i < b.N; i++ { - db.Update(func(tx *Tx) error { - return tx.Bucket("widgets").Put([]byte(strconv.Itoa(indexes[i])), value) - }) - } - }) -} - // withTempPath executes a function with a database reference. func withTempPath(fn func(string)) { f, _ := ioutil.TempFile("", "bolt-") @@ -513,12 +513,16 @@ func TestTx_OnCommit_Rollback(t *testing.T) { } // Benchmark the performance iterating over a cursor. -func BenchmarkTxCursor(b *testing.B) { - var total = 50000 +func BenchmarkTxCursor1(b *testing.B) { benchmarkTxCursor(b, 1) } +func BenchmarkTxCursor10(b *testing.B) { benchmarkTxCursor(b, 10) } +func BenchmarkTxCursor100(b *testing.B) { benchmarkTxCursor(b, 100) } +func BenchmarkTxCursor1000(b *testing.B) { benchmarkTxCursor(b, 1000) } +func BenchmarkTxCursor10000(b *testing.B) { benchmarkTxCursor(b, 10000) } + +func benchmarkTxCursor(b *testing.B, total int) { 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 { @@ -549,8 +553,14 @@ func BenchmarkTxCursor(b *testing.B) { } // Benchmark the performance of bulk put transactions in random order. -func BenchmarkTxPutRandom(b *testing.B) { - indexes := rand.Perm(b.N) +func BenchmarkTxPutRandom1(b *testing.B) { benchmarkTxPutRandom(b, 1) } +func BenchmarkTxPutRandom10(b *testing.B) { benchmarkTxPutRandom(b, 10) } +func BenchmarkTxPutRandom100(b *testing.B) { benchmarkTxPutRandom(b, 100) } +func BenchmarkTxPutRandom1000(b *testing.B) { benchmarkTxPutRandom(b, 1000) } +func BenchmarkTxPutRandom10000(b *testing.B) { benchmarkTxPutRandom(b, 10000) } + +func benchmarkTxPutRandom(b *testing.B, total int) { + indexes := rand.Perm(total) value := []byte(strings.Repeat("0", 64)) withOpenDB(func(db *DB, path string) { db.Update(func(tx *Tx) error { @@ -558,22 +568,30 @@ func BenchmarkTxPutRandom(b *testing.B) { }) var tx *Tx var bucket *Bucket - for i := 0; i < b.N; i++ { - if i%1000 == 0 { - if tx != nil { - tx.Commit() + for j := 0; j < b.N; j++ { + for i := 0; i < total; i++ { + if i%1000 == 0 { + if tx != nil { + tx.Commit() + } + tx, _ = db.Begin(true) + bucket = tx.Bucket("widgets") } - tx, _ = db.Begin(true) - bucket = tx.Bucket("widgets") + bucket.Put([]byte(strconv.Itoa(indexes[i])), value) } - bucket.Put([]byte(strconv.Itoa(indexes[i])), value) } tx.Commit() }) } // Benchmark the performance of bulk put transactions in sequential order. -func BenchmarkTxPutSequential(b *testing.B) { +func BenchmarkTxPutSequential1(b *testing.B) { benchmarkTxPutSequential(b, 1) } +func BenchmarkTxPutSequential10(b *testing.B) { benchmarkTxPutSequential(b, 10) } +func BenchmarkTxPutSequential100(b *testing.B) { benchmarkTxPutSequential(b, 100) } +func BenchmarkTxPutSequential1000(b *testing.B) { benchmarkTxPutSequential(b, 1000) } +func BenchmarkTxPutSequential10000(b *testing.B) { benchmarkTxPutSequential(b, 10000) } + +func benchmarkTxPutSequential(b *testing.B, total int) { value := []byte(strings.Repeat("0", 64)) withOpenDB(func(db *DB, path string) { db.Update(func(tx *Tx) error { @@ -581,8 +599,10 @@ func BenchmarkTxPutSequential(b *testing.B) { }) db.Update(func(tx *Tx) error { bucket := tx.Bucket("widgets") - for i := 0; i < b.N; i++ { - bucket.Put([]byte(strconv.Itoa(i)), value) + for j := 0; j < b.N; j++ { + for i := 0; i < total; i++ { + bucket.Put([]byte(strconv.Itoa(i)), value) + } } return nil }) |