Fat struct cache

master
Denis Palnitsky 3 years ago
parent c4ac8dd6f9
commit 76965f271e
No known key found for this signature in database
GPG Key ID: 37EEC9354AA9FD30

@ -85,6 +85,11 @@ Spoiler alert! The difference is insignificant.
| BenchmarkCacheGetStructNotExpiring-8 | 91921044 | 13.94 ns/op | 96379750 | 13.08 ns/op | | BenchmarkCacheGetStructNotExpiring-8 | 91921044 | 13.94 ns/op | 96379750 | 13.08 ns/op |
| BenchmarkCacheSetStructExpiring-8 | 13977464 | 86.44 ns/op | 13364509 | 87.69 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 | | 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 ### Reference

@ -679,3 +679,27 @@ func benchmarkCacheSetStruct(b *testing.B, exp time.Duration) {
tc.Set("foo", &TestStruct{Num: 1}, DefaultExpiration) 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++
}
}

Loading…
Cancel
Save