更新
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user