diff --git a/util/lru/lru_test.go b/util/lru/lru_test.go index 315c86218..cdc169f57 100644 --- a/util/lru/lru_test.go +++ b/util/lru/lru_test.go @@ -3,7 +3,10 @@ package lru -import "testing" +import ( + "math/rand" + "testing" +) func TestLRU(t *testing.T) { var c Cache[int, string] @@ -40,3 +43,17 @@ func TestLRU(t *testing.T) { t.Errorf("contains 3; should not") } } + +func BenchmarkLRU(b *testing.B) { + const lruSize = 10 + const maxval = 15 // 33% more keys than the LRU can hold + + c := Cache[int, bool]{MaxEntries: lruSize} + b.ReportAllocs() + for i := 0; i < b.N; i++ { + k := rand.Intn(maxval) + if !c.Get(k) { + c.Set(k, true) + } + } +}