neo-go/pkg/crypto/hash/merkle_bench_test.go
Roman Khimov 1b83dc2476 *: improve for loop syntax
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also
prefers ranging over slices where possible (it makes code a little better to
read).

Notice that we have a number of dangerous loops where slices are mutated
during loop execution, many of these can't be converted since we need proper
length evalutation at every iteration.

Signed-off-by: Roman Khimov <roman@nspcc.ru>
2024-08-30 21:45:18 +03:00

32 lines
655 B
Go

package hash_test
import (
"testing"
"github.com/nspcc-dev/neo-go/internal/random"
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
"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 {
hashes[i] = random.Uint256()
}
t.Run("NewMerkleTree", func(t *testing.B) {
t.ResetTimer()
for range t.N {
tr, err := hash.NewMerkleTree(hashes)
require.NoError(t, err)
_ = tr.Root()
}
})
t.Run("CalcMerkleRoot", func(t *testing.B) {
t.ResetTimer()
for range t.N {
_ = hash.CalcMerkleRoot(hashes)
}
})
}