2020-05-31 06:44:34 +00:00
|
|
|
package stateutil_test
|
2020-03-26 18:10:22 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-03-29 06:13:24 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/hashutil"
|
2020-06-18 02:15:13 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/htrutils"
|
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][:]
|
|
|
|
}
|
2020-06-18 02:15:13 +00:00
|
|
|
return htrutils.Merkleize(htrutils.NewHasherFunc(hashutil.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
|
|
|
}
|