mirror of https://github.com/hak5/bolt.git
Merge pull request #122 from mkobetic/benchmark_tweaks
Make all benchmarks constant size and add multiple sizesmaster
commit
e9c8f14d88
34
db_test.go
34
db_test.go
|
@ -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-")
|
||||
|
|
36
tx_test.go
36
tx_test.go
|
@ -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,7 +568,8 @@ func BenchmarkTxPutRandom(b *testing.B) {
|
|||
})
|
||||
var tx *Tx
|
||||
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 tx != nil {
|
||||
tx.Commit()
|
||||
|
@ -568,12 +579,19 @@ func BenchmarkTxPutRandom(b *testing.B) {
|
|||
}
|
||||
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,9 +599,11 @@ func BenchmarkTxPutSequential(b *testing.B) {
|
|||
})
|
||||
db.Update(func(tx *Tx) error {
|
||||
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)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue