mirror of
https://github.com/fluencelabs/tendermint
synced 2025-04-25 14:52:17 +00:00
consensus/WAL: benchmark WALDecode across data sizes
This commit is contained in:
parent
f9bc22ec6a
commit
42da8cd297
@ -134,7 +134,7 @@ func TestRmBadTx(t *testing.T) {
|
|||||||
checkTxRespCh <- struct{}{}
|
checkTxRespCh <- struct{}{}
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Error after CheckTx: %v", err)
|
t.Fatalf("Error after CheckTx: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for the tx
|
// check for the tx
|
||||||
|
@ -2,10 +2,13 @@ package consensus
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/rand"
|
||||||
"path"
|
"path"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
wire "github.com/tendermint/go-wire"
|
||||||
"github.com/tendermint/tendermint/consensus/types"
|
"github.com/tendermint/tendermint/consensus/types"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
@ -60,3 +63,66 @@ func TestSearchForEndHeight(t *testing.T) {
|
|||||||
assert.Equal(t, rs.Height, h+1, cmn.Fmt("wrong height"))
|
assert.Equal(t, rs.Height, h+1, cmn.Fmt("wrong height"))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var initOnce sync.Once
|
||||||
|
|
||||||
|
func registerInterfacesOnce() {
|
||||||
|
initOnce.Do(func() {
|
||||||
|
var _ = wire.RegisterInterface(
|
||||||
|
struct{ WALMessage }{},
|
||||||
|
wire.ConcreteType{[]byte{}, 0x10},
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func nBytes(n int) []byte {
|
||||||
|
buf := make([]byte, n)
|
||||||
|
n, _ = rand.Read(buf)
|
||||||
|
return buf[:n]
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkWalDecode(b *testing.B, n int) {
|
||||||
|
registerInterfacesOnce()
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
enc := NewWALEncoder(buf)
|
||||||
|
|
||||||
|
data := nBytes(n)
|
||||||
|
enc.Encode(&TimedWALMessage{Msg: data, Time: time.Now().Round(time.Second)})
|
||||||
|
|
||||||
|
encoded := buf.Bytes()
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
buf.Reset()
|
||||||
|
buf.Write(encoded)
|
||||||
|
dec := NewWALDecoder(buf)
|
||||||
|
if _, err := dec.Decode(); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkWalDecode512B(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 512)
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkWalDecode10KB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 10*1024)
|
||||||
|
}
|
||||||
|
func BenchmarkWalDecode100KB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 100*1024)
|
||||||
|
}
|
||||||
|
func BenchmarkWalDecode1MB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 1024*1024)
|
||||||
|
}
|
||||||
|
func BenchmarkWalDecode10MB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 10*1024*1024)
|
||||||
|
}
|
||||||
|
func BenchmarkWalDecode100MB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 100*1024*1024)
|
||||||
|
}
|
||||||
|
func BenchmarkWalDecode1GB(b *testing.B) {
|
||||||
|
benchmarkWalDecode(b, 1024*1024*1024)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user