github.com/prysmaticlabs/prysm@v1.4.4/shared/aggregation/maxcover_bench_test.go (about) 1 package aggregation 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/prysmaticlabs/go-bitfield" 8 aggtesting "github.com/prysmaticlabs/prysm/shared/aggregation/testing" 9 "github.com/prysmaticlabs/prysm/shared/params" 10 ) 11 12 func BenchmarkMaxCoverProblem_MaxCover(b *testing.B) { 13 bitlistLen := params.BeaconConfig().MaxValidatorsPerCommittee 14 tests := []struct { 15 numCandidates uint64 16 numMarkedBits uint64 17 allowOverlaps bool 18 }{ 19 { 20 numCandidates: 32, 21 numMarkedBits: 1, 22 }, 23 { 24 numCandidates: 128, 25 numMarkedBits: 1, 26 }, 27 { 28 numCandidates: 256, 29 numMarkedBits: 1, 30 }, 31 { 32 numCandidates: 32, 33 numMarkedBits: 8, 34 }, 35 { 36 numCandidates: 1024, 37 numMarkedBits: 8, 38 }, 39 { 40 numCandidates: 2048, 41 numMarkedBits: 8, 42 }, 43 { 44 numCandidates: 1024, 45 numMarkedBits: 32, 46 }, 47 { 48 numCandidates: 2048, 49 numMarkedBits: 32, 50 }, 51 { 52 numCandidates: 1024, 53 numMarkedBits: 128, 54 }, 55 { 56 numCandidates: 2048, 57 numMarkedBits: 128, 58 }, 59 { 60 numCandidates: 1024, 61 numMarkedBits: 512, 62 }, 63 { 64 numCandidates: 2048, 65 numMarkedBits: 512, 66 }, 67 } 68 for _, tt := range tests { 69 name := fmt.Sprintf("%d_attestations_with_%d_bit(s)_set", tt.numCandidates, tt.numMarkedBits) 70 b.Run(fmt.Sprintf("cur_%s", name), func(b *testing.B) { 71 b.StopTimer() 72 var bitlists []bitfield.Bitlist 73 if tt.numMarkedBits == 1 { 74 bitlists = aggtesting.BitlistsWithSingleBitSet(tt.numCandidates, bitlistLen) 75 } else { 76 bitlists = aggtesting.BitlistsWithMultipleBitSet(b, tt.numCandidates, bitlistLen, tt.numMarkedBits) 77 78 } 79 b.StartTimer() 80 for i := 0; i < b.N; i++ { 81 candidates := make([]*MaxCoverCandidate, len(bitlists)) 82 for i := 0; i < len(bitlists); i++ { 83 candidates[i] = NewMaxCoverCandidate(i, &bitlists[i]) 84 } 85 mc := &MaxCoverProblem{Candidates: candidates} 86 _, err := mc.Cover(len(bitlists), tt.allowOverlaps) 87 _ = err 88 } 89 }) 90 b.Run(fmt.Sprintf("new_%s", name), func(b *testing.B) { 91 b.StopTimer() 92 var bitlists []*bitfield.Bitlist64 93 if tt.numMarkedBits == 1 { 94 bitlists = aggtesting.Bitlists64WithSingleBitSet(tt.numCandidates, bitlistLen) 95 } else { 96 bitlists = aggtesting.Bitlists64WithMultipleBitSet(b, tt.numCandidates, bitlistLen, tt.numMarkedBits) 97 98 } 99 b.StartTimer() 100 for i := 0; i < b.N; i++ { 101 _, _, err := MaxCover(bitlists, len(bitlists), tt.allowOverlaps) 102 _ = err 103 } 104 }) 105 } 106 }