2020-05-31 06:44:34 +00:00
|
|
|
package stateutil_test
|
2020-03-26 18:10:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-15 22:55:11 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/crypto/hash"
|
2021-09-21 15:02:48 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/encoding/ssz"
|
2020-07-18 07:56:48 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
2020-03-26 18:10:22 +00:00
|
|
|
)
|
|
|
|
|
2020-07-21 02:05:23 +00:00
|
|
|
func BenchmarkMerkleize_Buffered(b *testing.B) {
|
2020-03-29 06:13:24 +00:00
|
|
|
roots := make([][32]byte, 8192)
|
|
|
|
for i := 0; i < 8192; i++ {
|
|
|
|
roots[0] = [32]byte{byte(i)}
|
|
|
|
}
|
|
|
|
|
|
|
|
newMerkleize := func(chunks [][32]byte, count uint64, limit uint64) ([32]byte, error) {
|
|
|
|
leafIndexer := func(i uint64) []byte {
|
|
|
|
return chunks[i][:]
|
|
|
|
}
|
2021-09-21 15:02:48 +00:00
|
|
|
return ssz.Merkleize(ssz.NewHasherFunc(hash.CustomSHA256Hasher()), count, limit, leafIndexer), nil
|
2020-03-29 06:13:24 +00:00
|
|
|
}
|
|
|
|
|
2020-07-21 02:05:23 +00:00
|
|
|
b.ResetTimer()
|
|
|
|
b.ReportAllocs()
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
_, err := newMerkleize(roots, 8192, 8192)
|
|
|
|
require.NoError(b, err)
|
|
|
|
}
|
2020-03-29 06:13:24 +00:00
|
|
|
}
|