V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
Nazz
V2EX  ›  分享创造

go memorycache v1.1.2 update: 使用四叉堆替换二叉堆

  •  
  •   Nazz · 195 天前 · 528 次点击
    这是一个创建于 195 天前的主题,其中的信息可能已经有所发展或是发生改变。

    GitHub

    四叉堆高度更低, 对 CPU 缓存更友好(Down 方法的 4 个比较操作有 3 个在相邻的同一层), 每个 Set 操作有几十纳秒的提升.

    benchmark

    从压测结果看, 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
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3307 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 00:38 · PVG 08:38 · LAX 17:38 · JFK 20:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.