prysm-pulse/beacon-chain/cache/benchmarks_test.go
Andrei Ivasko f99e2bd7c9 Benchmark active indices (#3153)
* new branch off master

* bloomfilter + benchmarks done

* cfilter benchmarks

* comments added

* goimports and gofmt added

* linter issues

* bazel run //:gazelle -- fix

* workspace definitions fixed

* fixed tree_test.go

* Update workspace

* final commit

* gazelle

* updated workspace

* workspace

* reverted workspace changes

* workspace newline

* applied git checkout origin/master WORKSPACE
2019-08-26 11:30:28 -05:00

46 lines
812 B
Go

package cache
import (
"testing"
)
var indices300k = createIndices(300000)
var epoch = uint64(1)
func createIndices(count int) *ActiveIndicesByEpoch {
indices := make([]uint64, 0, count)
for i := 0; i < count; i++ {
indices = append(indices, uint64(i))
}
return &ActiveIndicesByEpoch{
Epoch: epoch,
ActiveIndices: indices,
}
}
func BenchmarkCachingAddRetrieve(b *testing.B) {
c := NewActiveIndicesCache()
b.Run("ADD300K", func(b *testing.B) {
b.N = 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := c.AddActiveIndicesList(indices300k); err != nil {
b.Fatal(err)
}
}
})
b.Run("RETR300K", func(b *testing.B) {
b.N = 10
b.ResetTimer()
for i := 0; i < b.N; i++ {
if _, err := c.ActiveIndicesInEpoch(epoch); err != nil {
b.Fatal(err)
}
}
})
}