diff --git a/README.md b/README.md index c2969a7..7d1e1ca 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,11 @@ Spoiler alert! The difference is insignificant. | BenchmarkCacheGetStructNotExpiring-8 | 91921044 | 13.94 ns/op | 96379750 | 13.08 ns/op | | BenchmarkCacheSetStructExpiring-8 | 13977464 | 86.44 ns/op | 13364509 | 87.69 ns/op | | BenchmarkCacheSetStructNotExpiring-8 | 22749384 | 54.14 ns/op | 23207397 | 52.58 ns/op | +|BenchmarkCacheSetFatStructExpiring-8 | 11718718 | 103.3 ns/op | 12051895 | 102.3 ns/op | +|BenchmarkCacheGetFatStructNotExpiring-8 | 88695709 | 13.92 ns/op | 83220014 | 13.76 ns/op | + + + ### Reference diff --git a/cache_test.go b/cache_test.go index f1f5961..135c9ab 100644 --- a/cache_test.go +++ b/cache_test.go @@ -679,3 +679,27 @@ func benchmarkCacheSetStruct(b *testing.B, exp time.Duration) { tc.Set("foo", &TestStruct{Num: 1}, DefaultExpiration) } } + +func BenchmarkCacheSetFatStructExpiring(b *testing.B) { + b.StopTimer() + tc := New[*TestStruct](NoExpiration, 0) + b.StartTimer() + for i := 0; i < b.N; i++ { + tc.Set("foo", &TestStruct{Num: 1, Children: []*TestStruct{ + &TestStruct{Num: 2, Children: []*TestStruct{}}}}, DefaultExpiration) + } +} + +func BenchmarkCacheGetFatStructNotExpiring(b *testing.B) { + b.StopTimer() + tc := New[*TestStruct](NoExpiration, 0) + + tc.Set("foo", &TestStruct{Num: 1, Children: []*TestStruct{ + &TestStruct{Num: 2, Children: []*TestStruct{}}}}, DefaultExpiration) + b.StartTimer() + for i := 0; i < b.N; i++ { + st, _ := tc.Get("foo") + // just do something + st.Num++ + } +}