aboutsummaryrefslogtreecommitdiffstats
path: root/store_test.go
diff options
context:
space:
mode:
authorMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-24 10:37:50 +0530
committerMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-27 13:37:32 +0530
commita35f42bc2e4c29a1583fbc8900c14ec0ce5533d2 (patch)
tree5af6a2854644ac3dc44acdc9d604fa0eb576f120 /store_test.go
parentAdded LTR Eviction (diff)
downloadcache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar.gz
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar.bz2
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar.lz
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar.xz
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.tar.zst
cache-a35f42bc2e4c29a1583fbc8900c14ec0ce5533d2.zip
Added examples and documentation
Diffstat (limited to 'store_test.go')
-rw-r--r--store_test.go66
1 files changed, 53 insertions, 13 deletions
diff --git a/store_test.go b/store_test.go
index 3ad33e5..9b802bf 100644
--- a/store_test.go
+++ b/store_test.go
@@ -2,6 +2,7 @@ package cache
import (
"encoding/binary"
+ "fmt"
"testing"
"time"
@@ -132,24 +133,63 @@ func TestStoreClear(t *testing.T) {
}
func BenchmarkStoreGet(b *testing.B) {
- store := setupTestStore(b)
+ for n := 1; n <= 10000; n *= 10 {
+ b.Run(fmt.Sprint(n), func(b *testing.B) {
+ want := setupTestStore(b)
+ for i := range n - 1 {
+ buf := make([]byte, 8)
+ binary.LittleEndian.PutUint64(buf, uint64(i))
+ want.Set(buf, buf, 0)
+ }
+ key := []byte("Key")
+ want.Set(key, []byte("Store"), 0)
+ b.ReportAllocs()
- key := []byte("Key")
- store.Set(key, []byte("Store"), 0)
- b.ReportAllocs()
-
- for i := 0; i < b.N; i++ {
- store.Get(key)
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ want.Get(key)
+ }
+ })
}
}
func BenchmarkStoreSet(b *testing.B) {
- store := setupTestStore(b)
-
- key := []byte("Key")
- b.ReportAllocs()
+ for n := 1; n <= 10000; n *= 10 {
+ b.Run(fmt.Sprint(n), func(b *testing.B) {
+ want := setupTestStore(b)
+ for i := range n - 1 {
+ buf := make([]byte, 8)
+ binary.LittleEndian.PutUint64(buf, uint64(i))
+ want.Set(buf, buf, 0)
+ }
+ key := []byte("Key")
+ store := []byte("Store")
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ want.Set(key, store, 0)
+ }
+ })
+ }
+}
- for i := 0; i < b.N; i++ {
- store.Set(key, []byte("Store"), 0)
+func BenchmarkStoreDelete(b *testing.B) {
+ for n := 1; n <= 10000; n *= 10 {
+ b.Run(fmt.Sprint(n), func(b *testing.B) {
+ want := setupTestStore(b)
+ for i := range n - 1 {
+ buf := make([]byte, 8)
+ binary.LittleEndian.PutUint64(buf, uint64(i))
+ want.Set(buf, buf, 0)
+ }
+ key := []byte("Key")
+ store := []byte("Store")
+ b.ReportAllocs()
+ b.ResetTimer()
+ for i := 0; i < b.N; i++ {
+ want.Set(key, store, 0)
+ want.Delete(key)
+ }
+ })
}
}