make all benchmarks constant size and add multiple sizes

pull/34/head
Martin Kobetic 2014-04-08 20:53:54 +00:00
parent ac2d4f0336
commit 86cc692872
2 changed files with 35 additions and 49 deletions

View File

@ -5,11 +5,8 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"os" "os"
"regexp" "regexp"
"strconv"
"strings"
"testing" "testing"
"time" "time"
"unsafe" "unsafe"
@ -322,37 +319,6 @@ func TestDBString(t *testing.T) {
assert.Equal(t, db.GoString(), `bolt.DB{path:"/tmp/foo"}`) 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. // withTempPath executes a function with a database reference.
func withTempPath(fn func(string)) { func withTempPath(fn func(string)) {
f, _ := ioutil.TempFile("", "bolt-") f, _ := ioutil.TempFile("", "bolt-")

View File

@ -513,12 +513,16 @@ func TestTx_OnCommit_Rollback(t *testing.T) {
} }
// Benchmark the performance iterating over a cursor. // Benchmark the performance iterating over a cursor.
func BenchmarkTxCursor(b *testing.B) { func BenchmarkTxCursor1(b *testing.B) { benchmarkTxCursor(b, 1) }
var total = 50000 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) indexes := rand.Perm(total)
value := []byte(strings.Repeat("0", 100)) value := []byte(strings.Repeat("0", 100))
warn("X", b.N)
withOpenDB(func(db *DB, path string) { withOpenDB(func(db *DB, path string) {
// Write data to bucket. // Write data to bucket.
db.Update(func(tx *Tx) error { 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. // Benchmark the performance of bulk put transactions in random order.
func BenchmarkTxPutRandom(b *testing.B) { func BenchmarkTxPutRandom1(b *testing.B) { benchmarkTxPutRandom(b, 1) }
indexes := rand.Perm(b.N) 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)) value := []byte(strings.Repeat("0", 64))
withOpenDB(func(db *DB, path string) { withOpenDB(func(db *DB, path string) {
db.Update(func(tx *Tx) error { db.Update(func(tx *Tx) error {
@ -558,7 +568,8 @@ func BenchmarkTxPutRandom(b *testing.B) {
}) })
var tx *Tx var tx *Tx
var bucket *Bucket var bucket *Bucket
for i := 0; i < b.N; i++ { for j := 0; j < b.N; j++ {
for i := 0; i < total; i++ {
if i%1000 == 0 { if i%1000 == 0 {
if tx != nil { if tx != nil {
tx.Commit() tx.Commit()
@ -568,12 +579,19 @@ func BenchmarkTxPutRandom(b *testing.B) {
} }
bucket.Put([]byte(strconv.Itoa(indexes[i])), value) bucket.Put([]byte(strconv.Itoa(indexes[i])), value)
} }
}
tx.Commit() tx.Commit()
}) })
} }
// Benchmark the performance of bulk put transactions in sequential order. // 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)) value := []byte(strings.Repeat("0", 64))
withOpenDB(func(db *DB, path string) { withOpenDB(func(db *DB, path string) {
db.Update(func(tx *Tx) error { db.Update(func(tx *Tx) error {
@ -581,9 +599,11 @@ func BenchmarkTxPutSequential(b *testing.B) {
}) })
db.Update(func(tx *Tx) error { db.Update(func(tx *Tx) error {
bucket := tx.Bucket("widgets") bucket := tx.Bucket("widgets")
for i := 0; i < b.N; i++ { for j := 0; j < b.N; j++ {
for i := 0; i < total; i++ {
bucket.Put([]byte(strconv.Itoa(i)), value) bucket.Put([]byte(strconv.Itoa(i)), value)
} }
}
return nil return nil
}) })
}) })