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

Function BenchmarkLRU_Freq_NoExpire

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

Source from the content-addressed store, hash-verified

92}
93
94func BenchmarkLRU_Freq_NoExpire(b *testing.B) {
95 l := lru.NewLRU[int64, int64](8192, nil, 0)
96
97 trace := make([]int64, b.N*2)
98 for i := 0; i < b.N*2; i++ {
99 if i%2 == 0 {
100 trace[i] = getRand(b) % 16384
101 } else {
102 trace[i] = getRand(b) % 32768
103 }
104 }
105
106 b.ResetTimer()
107
108 for i := 0; i < b.N; i++ {
109 l.Add(trace[i], trace[i])
110 }
111 var hit, miss int
112 for i := 0; i < b.N; i++ {
113 if _, ok := l.Get(trace[i]); ok {
114 hit++
115 } else {
116 miss++
117 }
118 }
119 b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(hit+miss))
120}
121
122func BenchmarkLRU_Rand_WithExpire(b *testing.B) {
123 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