aboutsummaryrefslogtreecommitdiffstats
path: root/store_test.go
diff options
context:
space:
mode:
authorMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-28 18:09:36 +0530
committerMarc Pervaz Boocha <marcpervaz@qburst.com>2025-02-28 18:09:36 +0530
commita04c538db5df71fb8effb971cc9f9e3cc77ce3af (patch)
treef31d4f448a5b64a95e38915c8f4db3fcdad41585 /store_test.go
parentResizing imporvements and typo fixes (diff)
downloadcache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar.gz
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar.bz2
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar.lz
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar.xz
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.tar.zst
cache-a04c538db5df71fb8effb971cc9f9e3cc77ce3af.zip
Improved Concurency Part1
Diffstat (limited to 'store_test.go')
-rw-r--r--store_test.go82
1 files changed, 82 insertions, 0 deletions
diff --git a/store_test.go b/store_test.go
index cf8e58e..01af0c3 100644
--- a/store_test.go
+++ b/store_test.go
@@ -448,6 +448,47 @@ func BenchmarkStoreGet(b *testing.B) {
}
}
+func BenchmarkStoreGetParallel(b *testing.B) {
+ policy := map[string]EvictionPolicyType{
+ "None": PolicyNone,
+ "FIFO": PolicyFIFO,
+ "LRU": PolicyLRU,
+ "LFU": PolicyLFU,
+ "LTR": PolicyLTR,
+ }
+ for k, v := range policy {
+ b.Run(k, func(b *testing.B) {
+ for n := 1; n <= 10000; n *= 10 {
+ b.Run(strconv.Itoa(n), func(b *testing.B) {
+ want := setupTestStore(b)
+
+ if err := want.Policy.SetPolicy(v); err != nil {
+ b.Fatalf("unexpected error: %v", err)
+ }
+
+ 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()
+
+ b.ResetTimer()
+
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ want.Get(key)
+ }
+ })
+ })
+ }
+ })
+ }
+}
+
func BenchmarkStoreSet(b *testing.B) {
policy := map[string]EvictionPolicyType{
"None": PolicyNone,
@@ -478,6 +519,47 @@ func BenchmarkStoreSet(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
+ b.RunParallel(func(pb *testing.PB) {
+ for pb.Next() {
+ want.Set(key, store, 0)
+ }
+ })
+ })
+ }
+ })
+ }
+}
+
+func BenchmarkStoreSetParallel(b *testing.B) {
+ policy := map[string]EvictionPolicyType{
+ "None": PolicyNone,
+ "FIFO": PolicyFIFO,
+ "LRU": PolicyLRU,
+ "LFU": PolicyLFU,
+ "LTR": PolicyLTR,
+ }
+ for k, v := range policy {
+ b.Run(k, func(b *testing.B) {
+ for n := 1; n <= 10000; n *= 10 {
+ b.Run(strconv.Itoa(n), func(b *testing.B) {
+ want := setupTestStore(b)
+
+ if err := want.Policy.SetPolicy(v); err != nil {
+ b.Fatalf("unexpected error: %v", err)
+ }
+
+ 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 b.Loop() {
want.Set(key, store, 0)
}