zlog/benchmark_test.go

74 lines
1.4 KiB
Go
Raw Normal View History

2017-05-12 05:24:39 +00:00
package zerolog
import (
"errors"
"io/ioutil"
"testing"
"time"
2017-05-12 05:24:39 +00:00
)
var (
errExample = errors.New("fail")
fakeMessage = "Test logging, but use a somewhat realistic message length."
)
func BenchmarkLogEmpty(b *testing.B) {
logger := New(ioutil.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Log().Msg("")
}
})
}
func BenchmarkDisabled(b *testing.B) {
logger := New(ioutil.Discard).Level(Disabled)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().Msg(fakeMessage)
}
})
}
func BenchmarkInfo(b *testing.B) {
logger := New(ioutil.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().Msg(fakeMessage)
}
})
}
func BenchmarkContextFields(b *testing.B) {
logger := New(ioutil.Discard).With().
Str("string", "four!").
Time("time", time.Time{}).
Int("int", 123).
Float32("float", -2.203230293249593).
2017-05-12 05:24:39 +00:00
Logger()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().Msg(fakeMessage)
}
})
}
func BenchmarkLogFields(b *testing.B) {
logger := New(ioutil.Discard)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
logger.Info().
Str("string", "four!").
Time("time", time.Time{}).
Int("int", 123).
Float32("float", -2.203230293249593).
2017-05-12 05:24:39 +00:00
Msg(fakeMessage)
}
})
}