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

Function BenchmarkLRU_Rand_NoExpire

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

Source from the content-addressed store, hash-verified

67}
68
69func BenchmarkLRU_Rand_NoExpire(b *testing.B) {
70 l := lru.NewLRU[int64, int64](8192, nil, 0)
71
72 trace := make([]int64, b.N*2)
73 for i := 0; i < b.N*2; i++ {
74 trace[i] = getRand(b) % 32768
75 }
76
77 b.ResetTimer()
78
79 var hit, miss int
80 for i := 0; i < 2*b.N; i++ {
81 if i%2 == 0 {
82 l.Add(trace[i], trace[i])
83 } else {
84 if _, ok := l.Get(trace[i]); ok {
85 hit++
86 } else {
87 miss++
88 }
89 }
90 }
91 b.Logf("hit: %d miss: %d ratio: %f", hit, miss, float64(hit)/float64(hit+miss))
92}
93
94func BenchmarkLRU_Freq_NoExpire(b *testing.B) {
95 l := lru.NewLRU[int64, int64](8192, 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