prysm-pulse/shared/aggregation/attestations/attestations_bench_test.go
terence tsao d53539499c
Applies assertion funcs to shared tests (part 1) (#6626)
* Update kv aggregated_test.go
* Update block_test.go
* Update forkchoice_test.go
* Update unaggregated_test.go
* Update prepare_forkchoice_test.go
* Update prune_expired_test.go
* Update atts service_test.go
* Update service_attester_test.go
* Update service_proposer_test.go
* Upate exit service_test.go
* Gaz
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Move averageBalance from log.go to info.go
* Move avg balance from log.go to info.go
* Add info test
* Remove unused logEpochData in log.go
* Gaz
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* Merge branch 'master' of github.com:prysmaticlabs/prysm
* aggregation tests
* attestation util tests
* bench util tests
* block util tests
* herumi tests
* bytesutil tests
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Merge refs/heads/master into testutil-shared
* Update shared/aggregation/attestations/attestations_test.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
* Merge branch 'master' of github.com:prysmaticlabs/prysm into testutil-shared
* Fixed ordering
* Merge branch 'testutil-shared' of github.com:prysmaticlabs/prysm into testutil-shared
* Update shared/aggregation/attestations/attestations_test.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
* Update shared/bytesutil/bytes_test.go

Co-authored-by: Victor Farazdagi <simple.square@gmail.com>
2020-07-18 16:31:42 +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(b, 64, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 64),
},
},
{
name: "64 attestations with 8 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 8),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 64),
},
},
{
name: "64 attestations with 16 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 16),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 64),
},
},
{
name: "64 attestations with 32 random bits set",
inputs: aggtesting.BitlistsWithMultipleBitSet(b, 64, bitlistLen, 32),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 64),
},
},
{
name: "128 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(b, 128, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 128),
},
},
{
name: "256 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(b, 256, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 256),
},
},
{
name: "512 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(b, 512, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 512),
},
},
{
name: "1024 attestations with single bit set",
inputs: aggtesting.BitlistsWithSingleBitSet(b, 1024, bitlistLen),
want: []bitfield.Bitlist{
aggtesting.BitlistWithAllBitsSet(b, 1024),
},
},
}
for _, tt := range tests {
b.Run(tt.name, func(b *testing.B) {
atts := aggtesting.MakeAttestationsFromBitlists(b, tt.inputs)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := Aggregate(atts)
require.NoError(b, err)
}
})
}
}