prysm-pulse/slasher/db/kv/benchmark_test.go
Preston Van Loon 7cc32c4dda
Various code inspection resolutions (#7438)
* remove unused code

* remove defer use in loop

* Remove unused methods and constants

* gofmt and gaz

* nilness check

* remove unused args

* Add TODO for refactoring subscribeWithBase to remove unused arg. It seems too involved to include in this sweeping PR. https://github.com/prysmaticlabs/prysm/issues/7437

* replace empty slice declaration

* Remove unnecessary type conversions

* remove redundant type declaration

* rename receivers to be consistent

* Remove bootnode query tool. It is now obsolete by discv5

* Remove relay node. It is no longer used or supported

* Revert "Remove relay node. It is no longer used or supported"

This reverts commit 4bd7717334dad85ef4766ed9bc4da711fb5fa810.

* Delete unused test directory

* Delete unsupported gcp startup script

* Delete old k8s script

* build fixes

* fix build

* go mod tidy

* revert slasher/db/kv/block_header.go

* fix build

* remove redundant nil check

* combine func args

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2020-10-12 08:11:05 +00:00

99 lines
3.2 KiB
Go

package kv
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/slasher/detection/attestations/types"
)
const (
benchmarkValidator = 300000
)
func BenchmarkStore_SaveEpochSpans(b *testing.B) {
ctx := context.Background()
sigBytes := [2]byte{}
db := setupDB(b)
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
}
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := db.SaveEpochSpans(ctx, uint64(i%54000), es, false)
require.NoError(b, err, "Save validator span map failed")
}
}
func BenchmarkStore_EpochSpans(b *testing.B) {
db := setupDB(b)
ctx := context.Background()
sigBytes := [2]byte{}
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
}
b.Log(len(es.Bytes()))
for i := 0; i < 200; i++ {
err := db.SaveEpochSpans(ctx, uint64(i), es, false)
require.NoError(b, err, "Save validator span map failed")
}
b.Log(db.db.Info())
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := db.EpochSpans(ctx, uint64(i%200), false)
require.NoError(b, err, "Read validator span map failed")
}
}
func BenchmarkStore_GetValidatorSpan(b *testing.B) {
sigBytes := [2]byte{}
es := &types.EpochStore{}
es, err := es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
}
b.Log(len(es.Bytes()))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := es.GetValidatorSpan(uint64(i % benchmarkValidator))
require.NoError(b, err, "Read validator span map failed")
}
}
func BenchmarkStore_SetValidatorSpan(b *testing.B) {
sigBytes := [2]byte{}
var err error
es := &types.EpochStore{}
es, err = es.SetValidatorSpan(benchmarkValidator, types.Span{MinSpan: 1, MaxSpan: 2, SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
for i := 0; i < benchmarkValidator; i++ {
es, err = es.SetValidatorSpan(uint64(i), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
assert.NoError(b, err)
}
b.Log(len(es.Bytes()))
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
es, err = es.SetValidatorSpan(uint64(i%benchmarkValidator), types.Span{MinSpan: uint16(i), MaxSpan: uint16(benchmarkValidator - i), SigBytes: sigBytes, HasAttested: true})
require.NoError(b, err, "Read validator span map failed")
}
}