V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
lysShub
V2EX  ›  Go 编程语言

这两个 zap 的 bench 结果为什么差那么多?

  •  
  •   lysShub · 66 天前 · 1229 次点击
    这是一个创建于 66 天前的主题,其中的信息可能已经有所发展或是发生改变。
    8 条回复    2024-07-24 19:44:30 +08:00
    lysShub
        1
    lysShub  
    OP
       66 天前
    差了一个数量级

    go test -run=NONE -bench="Benchmark_Zap"
    goos: windows
    goarch: amd64
    pkg: bench
    cpu: Intel(R) Xeon(R) CPU E5-1650 v4 @ 3.60GHz
    Benchmark_Zap/sink-12 17067564 68.55 ns/op 2 B/op 0 allocs/op
    Benchmark_Zap/new-12 1000000 1038 ns/op 8 B/op 2 allocs/op
    PASS
    ok bench 3.021s
    matrix1010
        2
    matrix1010  
       66 天前
    discard 和 JSON encode 速度必然不一样。不过这个挺适合测试 LLM 的代码理解与基本逻辑能力,GPT-4o 3 次回答中 2 次都指出“sink” 应该更快 Potentially faster due to minimal overhead from discarding logs (discard:). 但 Gemini 1.5 pro 回答了 3 次全部错误,虽然他在分析代码时也指出了 discard ,但在后面推断哪个更快时直接忽略了这一点:Due to the simpler and more direct configuration in the `new` benchmark, it is **likely to be slightly faster** than the `sink` benchmark.
    lysShub
        3
    lysShub  
    OP
       66 天前
    @matrix1010 两个都是 discard
    matrix1010
        4
    matrix1010  
       66 天前
    @lysShub 确实,那最好 pprof 看一下
    lysShub
        5
    lysShub  
    OP
       66 天前
    @matrix1010 破案了,sink 那个的配置里面设置了 sample ,实际只有十分钟一的数据被真正序列化
    lysShub
        6
    lysShub  
    OP
       66 天前
    十分之一
    matrix1010
        7
    matrix1010  
       66 天前
    我刚才也 pprof 了一下你的代码,大头在 CheckEntity.Write 上。看了一眼 zap 代码其实是 1 秒内百分之一"with the same level and message in the same second, it will log every 100th entry with the same level and message in the same second." 不 sample 你的第二个应该更快一点,因为默认没有 caller
    keakon
        8
    keakon  
       66 天前
    zap 挺慢的,基本没啥奇技淫巧
    https://github.com/keakon/golog/?tab=readme-ov-file#result
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5527 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:29 · PVG 10:29 · LAX 19:29 · JFK 22:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.