prysm-pulse/shared/aggregation/attestations/attestations_bench_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

104 lines
2.9 KiB
Go

package attestations
import (
"testing"
"github.com/prysmaticlabs/go-bitfield"
aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bls/iface"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func BenchmarkAggregateAttestations_Aggregate(b *testing.B) {
// Override expensive BLS aggregation method with cheap no-op such that this benchmark profiles
// the logic of aggregation selection rather than BLS logic.
aggregateSignatures = func(sigs []iface.Signature) iface.Signature {
return sigs[0]
}
signatureFromBytes = func(sig []byte) (iface.Signature, error) {
return bls.NewAggregateSignature(), nil
}
defer func() {
aggregateSignatures = bls.AggregateSignatures
signatureFromBytes = bls.SignatureFromBytes
}()
bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee
tests := []struct {
name string
inputs []bitfield.Bitlist
want []bitfield.Bitlist
}{
{
name: "64 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(64, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(64),
},
},
{
name: "64 attestations with 8 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 8),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(64),
},
},
{
name: "64 attestations with 16 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 16),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(64),
},
},
{
name: "64 attestations with 32 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 32),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(64),
},
},
{
name: "128 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(128, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(128),
},
},
{
name: "256 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(256),
},
},
{
name: "512 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(512, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(512),
},
},
{
name: "1024 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(1024, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(1024),
},
},
}
for _, tt := range tests {
b.Run(tt.name, func(b *testing.B) {
atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Aggregate(atts)
require.NoError(b, err)
}
})
}
}