2017-05-12 05:24:39 +00:00
|
|
|
package zerolog
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
2017-05-20 02:43:59 +00:00
|
|
|
"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!").
|
2017-05-20 02:43:59 +00:00
|
|
|
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!").
|
2017-05-20 02:43:59 +00:00
|
|
|
Time("time", time.Time{}).
|
|
|
|
Int("int", 123).
|
|
|
|
Float32("float", -2.203230293249593).
|
2017-05-12 05:24:39 +00:00
|
|
|
Msg(fakeMessage)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|