添加自动文件压缩的实现
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package loggerx_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yuninks/loggerx"
|
||||
)
|
||||
|
||||
// 按大小切割开启后,每条日志会多一次 Stat(判断是否该滚动)的开销
|
||||
func BenchmarkWriteWithSizeSplit(b *testing.B) {
|
||||
l := benchLogger(b, loggerx.SetSizeSplit(8<<20))
|
||||
ctx := context.Background()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
l.Infof(ctx, "hello %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
// 不开大小切割的对照
|
||||
func BenchmarkWriteNoSizeSplit(b *testing.B) {
|
||||
l := benchLogger(b)
|
||||
ctx := context.Background()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
l.Infof(ctx, "hello %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
// 定时刷盘开启后(间隔取大值,避免刷盘本身干扰测量)
|
||||
func BenchmarkWriteWithFlushInterval(b *testing.B) {
|
||||
l := benchLogger(b, loggerx.SetFlushInterval(time.Hour))
|
||||
ctx := context.Background()
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
l.Infof(ctx, "hello %d", i)
|
||||
}
|
||||
}
|
||||
|
||||
// 定时刷盘:短间隔(1ms)下的稳态吞吐,含刷盘协程竞争
|
||||
func BenchmarkWriteShortFlushInterval(b *testing.B) {
|
||||
l := benchLogger(b, loggerx.SetFlushInterval(time.Millisecond))
|
||||
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