Skip to content

Commit 2091ebd

Browse files
DeVil2Oholiman
andauthored
trie: fix benchmark by ensuring key immutability (#28221)
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 <[email protected]>
1 parent 339a4cf commit 2091ebd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

trie/trie_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,9 @@ func benchGet(b *testing.B) {
614614
k := make([]byte, 32)
615615
for i := 0; i < benchElemCount; i++ {
616616
binary.LittleEndian.PutUint64(k, uint64(i))
617-
trie.MustUpdate(k, k)
617+
v := make([]byte, 32)
618+
binary.LittleEndian.PutUint64(v, uint64(i))
619+
trie.MustUpdate(k, v)
618620
}
619621
binary.LittleEndian.PutUint64(k, benchElemCount/2)
620622

@@ -630,8 +632,10 @@ func benchUpdate(b *testing.B, e binary.ByteOrder) *Trie {
630632
k := make([]byte, 32)
631633
b.ReportAllocs()
632634
for i := 0; i < b.N; i++ {
635+
v := make([]byte, 32)
633636
e.PutUint64(k, uint64(i))
634-
trie.MustUpdate(k, k)
637+
e.PutUint64(v, uint64(i))
638+
trie.MustUpdate(k, v)
635639
}
636640
return trie
637641
}

0 commit comments

Comments
 (0)