prysm-pulse/beacon-chain/state/stateutil/benchmark_test.go
Nishant Das cdac3d61ea
Custom Block HTR (#5219)
* add custom htr

* fix root

* fix everything

* Apply suggestions from code review

* Update beacon-chain/state/stateutil/blocks.go

* Update beacon-chain/blockchain/receive_block.go

Co-Authored-By: terence tsao <terence@prysmaticlabs.com>

* Update beacon-chain/blockchain/process_block.go

Co-Authored-By: terence tsao <terence@prysmaticlabs.com>

* terence's review

Co-authored-by: terence tsao <terence@prysmaticlabs.com>
Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
2020-03-26 13:10:22 -05:00

50 lines
1.2 KiB
Go

package stateutil_benchmark
import (
"testing"
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
"github.com/prysmaticlabs/go-ssz"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stateutil"
"github.com/prysmaticlabs/prysm/shared/testutil"
)
func BenchmarkBlockHTR(b *testing.B) {
genState, keys := testutil.DeterministicGenesisState(b, 200)
conf := testutil.DefaultBlockGenConfig()
blk, err := testutil.GenerateFullBlock(genState, keys, conf, 10)
if err != nil {
b.Fatal(err)
}
atts := make([]*ethpb.Attestation, 0, 128)
for i := 0; i < 128; i++ {
atts = append(atts, blk.Block.Body.Attestations[0])
}
deposits, _, err := testutil.DeterministicDepositsAndKeys(16)
if err != nil {
b.Fatal(err)
}
blk.Block.Body.Attestations = atts
blk.Block.Body.Deposits = deposits
b.Run("SSZ_HTR", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := ssz.HashTreeRoot(blk.Block); err != nil {
b.Fatal(err)
}
}
})
b.Run("Custom_SSZ_HTR", func(b *testing.B) {
b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
if _, err := stateutil.BlockRoot(blk.Block); err != nil {
b.Fatal(err)
}
}
})
}