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
146 天前
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.
我刚才也 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