mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-11 15:30:07 +00:00
1b83dc2476
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>
39 lines
904 B
Go
39 lines
904 B
Go
package mpt
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/nspcc-dev/neo-go/internal/random"
|
|
)
|
|
|
|
func benchmarkBytes(b *testing.B, n Node) {
|
|
inv := n.(interface{ invalidateCache() })
|
|
b.ReportAllocs()
|
|
b.ResetTimer()
|
|
for range b.N {
|
|
inv.invalidateCache()
|
|
_ = n.Bytes()
|
|
}
|
|
}
|
|
|
|
func BenchmarkBytes(b *testing.B) {
|
|
b.Run("extension", func(b *testing.B) {
|
|
n := NewExtensionNode(random.Bytes(10), NewLeafNode(random.Bytes(10)))
|
|
benchmarkBytes(b, n)
|
|
})
|
|
b.Run("leaf", func(b *testing.B) {
|
|
n := NewLeafNode(make([]byte, 15))
|
|
benchmarkBytes(b, n)
|
|
})
|
|
b.Run("hash", func(b *testing.B) {
|
|
n := NewHashNode(random.Uint256())
|
|
benchmarkBytes(b, n)
|
|
})
|
|
b.Run("branch", func(b *testing.B) {
|
|
n := NewBranchNode()
|
|
n.Children[0] = NewLeafNode(random.Bytes(10))
|
|
n.Children[4] = NewLeafNode(random.Bytes(10))
|
|
n.Children[7] = NewLeafNode(random.Bytes(10))
|
|
n.Children[8] = NewLeafNode(random.Bytes(10))
|
|
})
|
|
}
|