Skip to content

Commit

Permalink
trie: error check in benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
holiman committed Oct 28, 2021
1 parent 2787fe1 commit 9ea7c24
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions trie/difflayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package trie

import (
"bytes"
"math/rand"
"testing"

Expand Down Expand Up @@ -50,16 +51,19 @@ func emptyLayer() *diskLayer {

func benchmarkSearch(b *testing.B, depth int) {
var target []byte
var want []byte
// First, we set up 128 diff layers, with 3K items each
fill := func(parent snapshot, index int) *diffLayer {
var nodes = make(map[string]*cachedNode)
for i := 0; i < 3000; i++ {
hash := randomHash()
path := randomHash().Bytes()
key := EncodeInternalKey(path, hash)
nodes[string(key)] = randomNode()
val := randomNode()
nodes[string(key)] = val

if target == nil && depth == index {
want = val.rlp()
target = append([]byte{}, key...)
}
}
Expand All @@ -71,8 +75,18 @@ func benchmarkSearch(b *testing.B, depth int) {
layer = fill(layer, i)
}
b.ResetTimer()
var (
have []byte
err error
)
for i := 0; i < b.N; i++ {
layer.NodeBlob(target)
have, err = layer.NodeBlob(target)
if err != nil {
b.Fatal(err)
}
}
if !bytes.Equal(have, want) {
b.Fatalf("have %x want %x", have, want)
}
}

Expand Down

0 comments on commit 9ea7c24

Please sign in to comment.