V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
lysShub

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

  •  
  •   lysShub · Jul 24, 2024 · 2014 views
    This topic created in 646 days ago, the information mentioned may be changed or developed.
    8 replies    2024-07-24 19:44:30 +08:00
    lysShub
        1
    lysShub  
    OP
       Jul 24, 2024
    差了一个数量级

    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  
       Jul 24, 2024
    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
       Jul 24, 2024
    @matrix1010 两个都是 discard
    matrix1010
        4
    matrix1010  
       Jul 24, 2024
    @lysShub 确实,那最好 pprof 看一下
    lysShub
        5
    lysShub  
    OP
       Jul 24, 2024
    @matrix1010 破案了,sink 那个的配置里面设置了 sample ,实际只有十分钟一的数据被真正序列化
    lysShub
        6
    lysShub  
    OP
       Jul 24, 2024
    十分之一
    matrix1010
        7
    matrix1010  
       Jul 24, 2024
    我刚才也 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  
       Jul 24, 2024
    zap 挺慢的,基本没啥奇技淫巧
    https://github.com/keakon/golog/?tab=readme-ov-file#result
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2432 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 62ms · UTC 15:44 · PVG 23:44 · LAX 08:44 · JFK 11:44
    ♥ Do have faith in what you're doing.