Compare commits

...

1 Commits

Author SHA1 Message Date
485a6031ae sort-cli: add benchmark 2024-02-03 17:47:01 +03:00

View File

@ -1,6 +1,7 @@
package lru package lru
import ( import (
"fmt"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing" "testing"
"time" "time"
@ -76,3 +77,24 @@ func TestDummy(t *testing.T) { // for coverage 100% coverage
cache := New[int](0) cache := New[int](0)
cache.evict() 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
}
}
})
}