1 Star 0 Fork 13

Andy哥/go-logger

forked from phachon/go-logger 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
benchmark_test.go 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
phachon 提交于 2019-12-15 11:20 . update go mod
package go_logger
import (
"testing"
)
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleText"
func BenchmarkLoggerConsoleText(b *testing.B) {
logger := NewLogger()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
}
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleAsyncText"
func BenchmarkLoggerConsoleAsyncText(b *testing.B) {
logger := NewLogger()
logger.SetAsync()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
logger.Flush()
}
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="ConsoleJson"
func BenchmarkLoggerConsoleJson(b *testing.B) {
logger := NewLogger()
logger.Detach("console")
logger.Attach("console", LOGGER_LEVEL_DEBUG, &ConsoleConfig{
JsonFormat: true,
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
}
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="FileText"
func BenchmarkLoggerFileText(b *testing.B) {
logger := NewLogger()
logger.Detach("console")
logger.Attach("file", LOGGER_LEVEL_DEBUG, &FileConfig{
Filename: "./test.log",
DateSlice: "d",
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
}
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="AsyncText"
func BenchmarkLoggerFileAsyncText(b *testing.B) {
logger := NewLogger()
logger.Detach("console")
logger.Attach("file", LOGGER_LEVEL_DEBUG, &FileConfig{
Filename: "./test.log",
DateSlice: "d",
})
logger.SetAsync()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
logger.Flush()
}
// go test -run=benchmark -cpu=1,2,4 -benchmem -benchtime=3s -bench="FileJson"
func BenchmarkLoggerFileJson(b *testing.B) {
logger := NewLogger()
logger.Detach("console")
logger.Attach("file", LOGGER_LEVEL_DEBUG, &FileConfig{
Filename: "./test.log",
DateSlice: "d",
JsonFormat: true,
})
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info("benchmark logger message")
}
})
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/Wu-Andy/go-logger.git
git@gitee.com:Wu-Andy/go-logger.git
Wu-Andy
go-logger
go-logger
master

搜索帮助