github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/rpc/prysm/v1alpha1/validator/proposer_utils_bench_test.go (about) 1 package validator 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/prysmaticlabs/prysm/shared/copyutil" 8 9 "github.com/prysmaticlabs/go-bitfield" 10 ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 11 aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing" 12 "github.com/prysmaticlabs/prysm/shared/featureconfig" 13 "github.com/prysmaticlabs/prysm/shared/params" 14 ) 15 16 func BenchmarkProposerAtts_sortByProfitability(b *testing.B) { 17 bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee 18 19 tests := []struct { 20 name string 21 inputs []bitfield.Bitlist 22 }{ 23 { 24 name: "256 attestations with single bit set", 25 inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen), 26 }, 27 { 28 name: "256 attestations with 64 random bits set", 29 inputs: aggtesting.BitlistsWithSingleBitSet(256, bitlistLen), 30 }, 31 { 32 name: "512 attestations with single bit set", 33 inputs: aggtesting.BitlistsWithSingleBitSet(512, bitlistLen), 34 }, 35 { 36 name: "1024 attestations with 64 random bits set", 37 inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 64), 38 }, 39 { 40 name: "1024 attestations with 512 random bits set", 41 inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 512), 42 }, 43 { 44 name: "1024 attestations with 1000 random bits set", 45 inputs: aggtesting.BitlistsWithMultipleBitSet(b, 1024, bitlistLen, 1000), 46 }, 47 } 48 49 runner := func(atts []*ethpb.Attestation) { 50 attsCopy := make(proposerAtts, len(atts)) 51 for i, att := range atts { 52 attsCopy[i] = copyutil.CopyAttestation(att) 53 } 54 attsCopy.sortByProfitability() 55 } 56 57 for _, tt := range tests { 58 b.Run(fmt.Sprintf("naive_%s", tt.name), func(b *testing.B) { 59 b.StopTimer() 60 resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{ 61 ProposerAttsSelectionUsingMaxCover: false, 62 }) 63 defer resetCfg() 64 atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs) 65 b.StartTimer() 66 for i := 0; i < b.N; i++ { 67 runner(atts) 68 } 69 }) 70 b.Run(fmt.Sprintf("max-cover_%s", tt.name), func(b *testing.B) { 71 b.StopTimer() 72 resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{ 73 ProposerAttsSelectionUsingMaxCover: true, 74 }) 75 defer resetCfg() 76 atts := aggtesting.MakeAttestationsFromBitlists(tt.inputs) 77 b.StartTimer() 78 for i := 0; i < b.N; i++ { 79 runner(atts) 80 } 81 }) 82 } 83 }