This commit is contained in:
yun
2026-09-14 00:14:30 +08:00
parent 316c6420a7
commit 7e1b474823
20 changed files with 1885 additions and 166 deletions
+22
View File
@@ -51,3 +51,25 @@ func BenchmarkWriteShortFlushInterval(b *testing.B) {
l.Infof(ctx, "hello %d", i)
}
}
// text 格式(不走 encoding/json,应该比默认 JSON 便宜)
func BenchmarkTextFormat(b *testing.B) {
l := benchLogger(b, loggerx.SetFormat(loggerx.FormatText))
ctx := context.Background()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
l.Infof(ctx, "hello %d", i)
}
}
// 带前缀的 JSON(每行多一次拼接)
func BenchmarkJSONWithPrefix(b *testing.B) {
l := benchLogger(b, loggerx.SetPrefix("[svc] "))
ctx := context.Background()
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
l.Infof(ctx, "hello %d", i)
}
}