代码拉取完成,页面将自动刷新
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")
}
})
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。