Skip to content

Commit

Permalink
trie: fix benchmark by ensuring key immutability (ethereum#28221)
Browse files Browse the repository at this point in the history
This change fixes the bug in a benchmark, where the input to the trie is reused in a way which is not correct. 

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
  • Loading branch information
2 people authored and devopsbo3 committed Nov 10, 2023
1 parent 3c77c17 commit ce21829
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,9 @@ func benchGet(b *testing.B) {
k := make([]byte, 32)
for i := 0; i < benchElemCount; i++ {
binary.LittleEndian.PutUint64(k, uint64(i))
trie.MustUpdate(k, k)
v := make([]byte, 32)
binary.LittleEndian.PutUint64(v, uint64(i))
trie.MustUpdate(k, v)
}
binary.LittleEndian.PutUint64(k, benchElemCount/2)

Expand All @@ -630,8 +632,10 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
k := make([]byte, 32)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
v := make([]byte, 32)
e.PutUint64(k, uint64(i))
trie.MustUpdate(k, k)
e.PutUint64(v, uint64(i))
trie.MustUpdate(k, v)
}
return trie
}
Expand Down

0 comments on commit ce21829

Please sign in to comment.