四叉堆高度更低, 对 CPU 缓存更友好(Down 方法的 4 个比较操作有 3 个在相邻的同一层), 每个 Set 操作有几十纳秒的提升.
从压测结果看, MemoryCache 的 Get 性能略高于 Ristretto, Set 性能远高于它. https://github.com/lxzan/memorycache/blob/main/benchmark/benchmark_test.go
go test -benchmem -run=^$ -bench . github.com/lxzan/memorycache/benchmark
goos: linux
goarch: amd64
pkg: github.com/lxzan/memorycache/benchmark
cpu: AMD Ryzen 5 PRO 4650G with Radeon Graphics
BenchmarkMemoryCache_Set-12 11499579 101.7 ns/op 16 B/op 0 allocs/op
BenchmarkMemoryCache_Get-12 26326636 45.97 ns/op 0 B/op 0 allocs/op
BenchmarkRistretto_Set-12 12341542 275.4 ns/op 119 B/op 2 allocs/op
BenchmarkRistretto_Get-12 22825676 50.12 ns/op 16 B/op 1 allocs/op
PASS
ok github.com/lxzan/memorycache/benchmark 20.107s