mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-30 15:01:35 +00:00
d52e79668b
NewMerkleTree is a memory hog, we can do better than that: BenchmarkMerkle/NewMerkleTree-8 13 88434670 ns/op 20828207 B/op 300035 allocs/op BenchmarkMerkle/CalcMerkleRoot-8 15 69264150 ns/op 0 B/op 0 allocs/op
37 lines
739 B
Go
37 lines
739 B
Go
package hash
|
|
|
|
import (
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func BenchmarkMerkle(t *testing.B) {
|
|
var err error
|
|
var hashes = make([]util.Uint256, 100000)
|
|
var h = make([]byte, 32)
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
for i := range hashes {
|
|
r.Read(h)
|
|
hashes[i], err = util.Uint256DecodeBytesBE(h)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
t.Run("NewMerkleTree", func(t *testing.B) {
|
|
t.ResetTimer()
|
|
for n := 0; n < t.N; n++ {
|
|
tr, err := NewMerkleTree(hashes)
|
|
require.NoError(t, err)
|
|
_ = tr.Root()
|
|
}
|
|
})
|
|
t.Run("CalcMerkleRoot", func(t *testing.B) {
|
|
t.ResetTimer()
|
|
for n := 0; n < t.N; n++ {
|
|
_ = CalcMerkleRoot(hashes)
|
|
}
|
|
})
|
|
}
|