tendermint/lite/performance_test.go

117 lines
2.6 KiB
Go
Raw Normal View History

2017-11-09 14:37:18 -08:00
package lite_test
2017-10-24 03:34:36 -07:00
import (
"fmt"
"testing"
2017-11-09 14:37:18 -08:00
"github.com/tendermint/tendermint/lite"
2017-10-24 03:34:36 -07:00
)
func BenchmarkGenCommit20(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(20)
2017-10-24 03:34:36 -07:00
benchmarkGenCommit(b, keys)
}
func BenchmarkGenCommit100(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(100)
2017-10-24 03:34:36 -07:00
benchmarkGenCommit(b, keys)
}
func BenchmarkGenCommitSec20(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(20)
2017-10-24 03:34:36 -07:00
benchmarkGenCommit(b, keys)
}
func BenchmarkGenCommitSec100(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(100)
2017-10-24 03:34:36 -07:00
benchmarkGenCommit(b, keys)
}
2017-11-09 14:37:18 -08:00
func benchmarkGenCommit(b *testing.B, keys lite.ValKeys) {
2017-10-24 03:34:36 -07:00
chainID := fmt.Sprintf("bench-%d", len(keys))
vals := keys.ToValidators(20, 10)
for i := 0; i < b.N; i++ {
h := int64(1 + i)
2017-10-24 03:34:36 -07:00
appHash := []byte(fmt.Sprintf("h=%d", h))
keys.GenCommit(chainID, h, nil, vals, appHash, 0, len(keys))
}
}
// this benchmarks generating one key
func BenchmarkGenValKeys(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(20)
2017-10-24 03:34:36 -07:00
for i := 0; i < b.N; i++ {
keys = keys.Extend(1)
}
}
// this benchmarks generating one key
func BenchmarkGenSecpValKeys(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(20)
2017-10-24 03:34:36 -07:00
for i := 0; i < b.N; i++ {
keys = keys.Extend(1)
}
}
func BenchmarkToValidators20(b *testing.B) {
benchmarkToValidators(b, 20)
}
func BenchmarkToValidators100(b *testing.B) {
benchmarkToValidators(b, 100)
}
// this benchmarks constructing the validator set (.PubKey() * nodes)
func benchmarkToValidators(b *testing.B, nodes int) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(nodes)
2017-10-24 03:34:36 -07:00
for i := 1; i <= b.N; i++ {
keys.ToValidators(int64(2*i), int64(i))
}
}
func BenchmarkToValidatorsSec100(b *testing.B) {
benchmarkToValidatorsSec(b, 100)
}
// this benchmarks constructing the validator set (.PubKey() * nodes)
func benchmarkToValidatorsSec(b *testing.B, nodes int) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(nodes)
2017-10-24 03:34:36 -07:00
for i := 1; i <= b.N; i++ {
keys.ToValidators(int64(2*i), int64(i))
}
}
func BenchmarkCertifyCommit20(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(20)
2017-10-24 03:34:36 -07:00
benchmarkCertifyCommit(b, keys)
}
func BenchmarkCertifyCommit100(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenValKeys(100)
2017-10-24 03:34:36 -07:00
benchmarkCertifyCommit(b, keys)
}
func BenchmarkCertifyCommitSec20(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(20)
2017-10-24 03:34:36 -07:00
benchmarkCertifyCommit(b, keys)
}
func BenchmarkCertifyCommitSec100(b *testing.B) {
2017-11-09 14:37:18 -08:00
keys := lite.GenSecpValKeys(100)
2017-10-24 03:34:36 -07:00
benchmarkCertifyCommit(b, keys)
}
2017-11-09 14:37:18 -08:00
func benchmarkCertifyCommit(b *testing.B, keys lite.ValKeys) {
2017-10-24 03:34:36 -07:00
chainID := "bench-certify"
vals := keys.ToValidators(20, 10)
2017-11-09 14:37:18 -08:00
cert := lite.NewStatic(chainID, vals)
2017-10-24 03:34:36 -07:00
check := keys.GenCommit(chainID, 123, nil, vals, []byte("foo"), 0, len(keys))
for i := 0; i < b.N; i++ {
err := cert.Certify(check)
if err != nil {
panic(err)
}
}
}