@@ -112,11 +112,29 @@ func BenchmarkEncodeShortNode(b *testing.B) {
112112 }
113113}
114114
115+ // goos: darwin
116+ // goarch: arm64
117+ // pkg: github.com/ethereum/go-ethereum/trie
118+ // BenchmarkEncodeFullNode
119+ // BenchmarkEncodeFullNode-8 4323273 284.4 ns/op 576 B/op 1 allocs/op
120+ func BenchmarkEncodeFullNode (b * testing.B ) {
121+ node := & fullNode {}
122+ for i := 0 ; i < 16 ; i ++ {
123+ node .Children [i ] = hashNode (randBytes (32 ))
124+ }
125+ b .ResetTimer ()
126+ b .ReportAllocs ()
127+
128+ for i := 0 ; i < b .N ; i ++ {
129+ nodeToBytes (node )
130+ }
131+ }
132+
115133// goos: darwin
116134// goarch: arm64
117135// pkg: github.com/ethereum/go-ethereum/trie
118136// BenchmarkDecodeShortNode
119- // BenchmarkDecodeShortNode-8 9125304 129.2 ns/op 109 B/op 3 allocs/op
137+ // BenchmarkDecodeShortNode-8 7925638 151.0 ns/op 157 B/op 4 allocs/op
120138func BenchmarkDecodeShortNode (b * testing.B ) {
121139 node := & shortNode {
122140 Key : []byte {0x1 , 0x2 },
@@ -136,26 +154,29 @@ func BenchmarkDecodeShortNode(b *testing.B) {
136154// goos: darwin
137155// goarch: arm64
138156// pkg: github.com/ethereum/go-ethereum/trie
139- // BenchmarkEncodeFullNode
140- // BenchmarkEncodeFullNode -8 4323273 284.4 ns/op 576 B/op 1 allocs/op
141- func BenchmarkEncodeFullNode (b * testing.B ) {
142- node := & fullNode {}
143- for i := 0 ; i < 16 ; i ++ {
144- node . Children [ i ] = hashNode (randBytes (32 ))
157+ // BenchmarkDecodeShortNodeUnsafe
158+ // BenchmarkDecodeShortNodeUnsafe -8 9027476 128.6 ns/op 109 B/op 3 allocs/op
159+ func BenchmarkDecodeShortNodeUnsafe (b * testing.B ) {
160+ node := & shortNode {
161+ Key : [] byte { 0x1 , 0x2 },
162+ Val : hashNode (randBytes (32 )),
145163 }
164+ blob := nodeToBytes (node )
165+ hash := crypto .Keccak256 (blob )
166+
146167 b .ResetTimer ()
147168 b .ReportAllocs ()
148169
149170 for i := 0 ; i < b .N ; i ++ {
150- nodeToBytes ( node )
171+ mustDecodeNodeUnsafe ( hash , blob )
151172 }
152173}
153174
154175// goos: darwin
155176// goarch: arm64
156177// pkg: github.com/ethereum/go-ethereum/trie
157178// BenchmarkDecodeFullNode
158- // BenchmarkDecodeFullNode-8 1789374 671.4 ns/op 704 B/op 17 allocs/op
179+ // BenchmarkDecodeFullNode-8 1597462 761.9 ns/op 1280 B/op 18 allocs/op
159180func BenchmarkDecodeFullNode (b * testing.B ) {
160181 node := & fullNode {}
161182 for i := 0 ; i < 16 ; i ++ {
@@ -171,3 +192,24 @@ func BenchmarkDecodeFullNode(b *testing.B) {
171192 mustDecodeNode (hash , blob )
172193 }
173194}
195+
196+ // goos: darwin
197+ // goarch: arm64
198+ // pkg: github.com/ethereum/go-ethereum/trie
199+ // BenchmarkDecodeFullNodeUnsafe
200+ // BenchmarkDecodeFullNodeUnsafe-8 1789070 687.1 ns/op 704 B/op 17 allocs/op
201+ func BenchmarkDecodeFullNodeUnsafe (b * testing.B ) {
202+ node := & fullNode {}
203+ for i := 0 ; i < 16 ; i ++ {
204+ node .Children [i ] = hashNode (randBytes (32 ))
205+ }
206+ blob := nodeToBytes (node )
207+ hash := crypto .Keccak256 (blob )
208+
209+ b .ResetTimer ()
210+ b .ReportAllocs ()
211+
212+ for i := 0 ; i < b .N ; i ++ {
213+ mustDecodeNodeUnsafe (hash , blob )
214+ }
215+ }
0 commit comments