2024-08-30 12:48:13 +00:00
|
|
|
package hash_test
|
2020-09-15 15:38:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-08-30 12:48:13 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/internal/random"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
2020-09-15 15:38:15 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkMerkle(t *testing.B) {
|
|
|
|
var hashes = make([]util.Uint256, 100000)
|
|
|
|
for i := range hashes {
|
2024-08-30 12:48:13 +00:00
|
|
|
hashes[i] = random.Uint256()
|
2020-09-15 15:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("NewMerkleTree", func(t *testing.B) {
|
|
|
|
t.ResetTimer()
|
2024-08-30 18:41:02 +00:00
|
|
|
for range t.N {
|
2024-08-30 12:48:13 +00:00
|
|
|
tr, err := hash.NewMerkleTree(hashes)
|
2020-09-15 15:38:15 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
_ = tr.Root()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("CalcMerkleRoot", func(t *testing.B) {
|
|
|
|
t.ResetTimer()
|
2024-08-30 18:41:02 +00:00
|
|
|
for range t.N {
|
2024-08-30 12:48:13 +00:00
|
|
|
_ = hash.CalcMerkleRoot(hashes)
|
2020-09-15 15:38:15 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|