Allocate the appropriate memory for retrieveIndicesFromBitfield (#6507)

* Allocate the appropriate memory for retrieveIndicesFromBitfield
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
* Merge refs/heads/master into memory0
This commit is contained in:
Preston Van Loon 2020-07-07 22:47:26 -07:00 committed by GitHub
parent fd9003f822
commit a02553815f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 2 deletions

View File

@ -22,7 +22,10 @@ go_library(
go_test(
name = "go_default_test",
srcs = ["status_test.go"],
srcs = [
"benchmark_test.go",
"status_test.go",
],
embed = [":go_default_library"],
deps = [
"//proto/beacon/p2p/v1:go_default_library",

View File

@ -0,0 +1,18 @@
package peers
import (
"testing"
"github.com/prysmaticlabs/go-bitfield"
)
func Benchmark_retrieveIndicesFromBitfield(b *testing.B) {
bv := bitfield.NewBitvector64()
for i := uint64(0); i < bv.Len(); i++ {
bv.SetBitAt(i, true)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
retrieveIndicesFromBitfield(bv)
}
}

View File

@ -493,7 +493,7 @@ func (p *Status) HighestEpoch() uint64 {
}
func retrieveIndicesFromBitfield(bitV bitfield.Bitvector64) []uint64 {
committeeIdxs := []uint64{}
committeeIdxs := make([]uint64, 0, bitV.Count())
for i := uint64(0); i < 64; i++ {
if bitV.BitAt(i) {
committeeIdxs = append(committeeIdxs, i)