V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
如果想在 V2EX 获得更好的推广效果,欢迎了解 PRO 会员机制:
https://www.v2ex.com/pro/about
newmiao
V2EX  ›  推广

一个 8byte 的内存优化

  •  
  •   newmiao · Sep 2, 2021 · 1711 views
    This topic created in 1712 days ago, the information mentioned may be changed or developed.

    最近看 Dave Cheney 的一篇文章,发现一个有趣的代码片段,里面提到了一个 8byte 的内存优化。

    代码片段是这样的:

    func BenchmarkSortStrings(b *testing.B) {
     s := []string{"heart", "lungs", "brain", "kidneys", "pancreas"}
     b.ReportAllocs()
     for i := 0; i < b.N; i++ {
      var ss sort.StringSlice = s
      var si sort.Interface = ss
      sort.Sort(si)
     }
    }
    

    代码很简单,是对一个[]string做排序的内存分配压测

    详见 传送门

    ligiggy
        1
    ligiggy  
       Sep 2, 2021   ❤️ 1
    @Livid 推广嫌疑
    Livid
        2
    Livid  
    MOD
    PRO
       Sep 2, 2021
    @ligiggy 谢谢。

    @newmiao 请阅读 V2EX 的节点使用指南:

    https://www.v2ex.com/help/node

    如果你要推广自己的公众号,请发到 /go/promotions 节点。这个主题已经被移动。
    newmiao
        3
    newmiao  
    OP
       Sep 10, 2021
    @Livid ok
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3465 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 11:18 · PVG 19:18 · LAX 04:18 · JFK 07:18
    ♥ Do have faith in what you're doing.