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

Function BenchmarkLRU_Rand_WithExpire

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

Source from the content-addressed store, hash-verified

120}
121
122func BenchmarkLRU_Rand_WithExpire(b *testing.B) {
123 l := lru.NewLRU[int64, int64](8192, nil, time.Millisecond*10)
124
125 trace := make([]int64, b.N*2)
126 for i := 0; i < b.N*2; i++ {
127 trace[i] = getRand(b) % 32768
128 }
129
130 b.ResetTimer()
131
132 var hit, miss int
133 for i := 0; i < 2*b.N; i++ {
134 if i%2 == 0 {
135 l.Add(trace[i], trace[i])
136 } else {
137 if _, ok := l.Get(trace[i]); ok {
138 hit++
139 } else {
140 miss++
141 }
142 }
143 }
144 b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(hit+miss))
145}
146
147func BenchmarkLRU_Freq_WithExpire(b *testing.B) {
148 l := lru.NewLRU[int64, int64](8192, nil, time.Millisecond*10)

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