Compare commits
1 Commits
renovate/c
...
485a6031ae
Author | SHA1 | Date | |
---|---|---|---|
485a6031ae
|
@@ -1,6 +1,7 @@
|
||||
package lru
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -76,3 +77,24 @@ func TestDummy(t *testing.T) { // for coverage 100% coverage
|
||||
cache := New[int](0)
|
||||
cache.evict()
|
||||
}
|
||||
|
||||
// We will be storing many short strings as the key and value
|
||||
func Benchmark(b *testing.B) {
|
||||
cache := New[string](10)
|
||||
ttl := 1000 * time.Millisecond
|
||||
|
||||
b.Run("Set", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
cache.Set(fmt.Sprintf("item:%d", i), fmt.Sprintf("item:%d", i), ttl)
|
||||
}
|
||||
})
|
||||
|
||||
b.Run("Get", func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
value, ok := cache.Get(fmt.Sprintf("item:%d", i))
|
||||
if ok {
|
||||
_ = value
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user