diff options
author | Martin Kobetic <mkobetic@gmail.com> | 2014-04-08 20:53:54 +0000 |
---|---|---|
committer | Martin Kobetic <mkobetic@gmail.com> | 2014-04-08 20:53:54 +0000 |
commit | 86cc69287202a0d0493b06b8b775157887a0a1ff (patch) | |
tree | 58fae5c421b191cc6f0a5a54b20600bcc7cd9fa2 | |
parent | Merge branch 'master' of https://github.com/boltdb/bolt (diff) | |
download | dedo-86cc69287202a0d0493b06b8b775157887a0a1ff.tar.gz dedo-86cc69287202a0d0493b06b8b775157887a0a1ff.tar.xz |
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 }) |