From a04c538db5df71fb8effb971cc9f9e3cc77ce3af Mon Sep 17 00:00:00 2001 From: Marc Pervaz Boocha Date: Fri, 28 Feb 2025 18:09:36 +0530 Subject: Improved Concurency Part1 --- store_test.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) (limited to 'store_test.go') diff --git a/store_test.go b/store_test.go index cf8e58e..01af0c3 100644 --- a/store_test.go +++ b/store_test.go @@ -448,7 +448,89 @@ 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, + "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() + + 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, -- cgit v1.2.3-70-g09d2