MCPcopy
hub / github.com/go-gorm/gorm / BenchmarkLRU_Freq_WithExpire

Function BenchmarkLRU_Freq_WithExpire

tests/lru_test.go:147–173  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

145}
146
147func BenchmarkLRU_Freq_WithExpire(b *testing.B) {
148 l := lru.NewLRU[int64, int64](8192, nil, time.Millisecond*10)
149
150 trace := make([]int64, b.N*2)
151 for i := 0; i < b.N*2; i++ {
152 if i%2 == 0 {
153 trace[i] = getRand(b) % 16384
154 } else {
155 trace[i] = getRand(b) % 32768
156 }
157 }
158
159 b.ResetTimer()
160
161 for i := 0; i < b.N; i++ {
162 l.Add(trace[i], trace[i])
163 }
164 var hit, miss int
165 for i := 0; i < b.N; i++ {
166 if _, ok := l.Get(trace[i]); ok {
167 hit++
168 } else {
169 miss++
170 }
171 }
172 b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(hit+miss))
173}
174
175func TestLRUNoPurge(t *testing.T) {
176 lc := lru.NewLRU[string, string](10, nil, 0)

Callers

nothing calls this directly

Calls 4

NewLRUFunction · 0.92
getRandFunction · 0.85
AddMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected