From ce2182937b4ded7e795831c5c045a42a664e8784 Mon Sep 17 00:00:00 2001 From: Chirag Garg <38765776+DeVil2O@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:16:22 +0530 Subject: [PATCH] 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 --- trie/trie_test.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/trie/trie_test.go b/trie/trie_test.go index 35ccc772010c..8078770e7a37 100644 --- a/trie/trie_test.go +++ b/trie/trie_test.go @@ -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) @@ -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 }