github.com/bibaroc/wingman@v0.0.2-0.20200911182922-33c2085136b1/pkg/logger/logger_parallel_test.go (about) 1 package logger_test 2 3 import ( 4 "fmt" 5 "io/ioutil" 6 "log" 7 "testing" 8 9 "github.com/bibaroc/wingman/pkg/logger" 10 pglog "github.com/go-playground/log/v7" 11 "github.com/go-playground/log/v7/handlers/console" 12 ) 13 14 func BenchmarkLoggerParallelCustom(b *testing.B) { 15 log := logger.NewLogger(logger.ERROR, ioutil.Discard, 0) 16 b.SetBytes(int64(len(short))) 17 18 b.ResetTimer() 19 20 b.RunParallel(func(pb *testing.PB) { 21 for pb.Next() { 22 log.Errorln(short) 23 } 24 }) 25 } 26 func BenchmarkLoggerParallelStd(b *testing.B) { 27 log := log.New(ioutil.Discard, "std", 0) 28 b.SetBytes(int64(len(short))) 29 30 b.ResetTimer() 31 32 b.RunParallel(func(pb *testing.PB) { 33 for pb.Next() { 34 log.Println(short) 35 } 36 }) 37 } 38 39 func BenchmarkLoggerParallelPlayground(b *testing.B) { 40 csole := console.New(false) 41 csole.SetDisplayColor(false) 42 csole.SetWriter(ioutil.Discard) 43 pglog.AddHandler(csole, pglog.AllLevels...) 44 b.SetBytes(int64(len(short))) 45 46 b.ResetTimer() 47 48 b.RunParallel(func(pb *testing.PB) { 49 for pb.Next() { 50 pglog.Debug(short) 51 } 52 }) 53 } 54 func BenchmarkLoggerParallelCustomWCaller(b *testing.B) { 55 log := logger.NewLogger(logger.ERROR, ioutil.Discard, logger.WithCallerInfo) 56 b.SetBytes(int64(len(short))) 57 58 b.ResetTimer() 59 60 b.RunParallel(func(pb *testing.PB) { 61 for pb.Next() { 62 log.Errorln(short) 63 } 64 }) 65 } 66 func BenchmarkLoggerParallelStdWCaller(b *testing.B) { 67 log := log.New(ioutil.Discard, "std", log.Lshortfile) 68 b.SetBytes(int64(len(short))) 69 70 b.ResetTimer() 71 72 b.RunParallel(func(pb *testing.PB) { 73 for pb.Next() { 74 log.Println(short) 75 } 76 }) 77 } 78 func BenchmarkLoggerParallelFmt(b *testing.B) { 79 b.SetBytes(int64(len(short))) 80 81 b.ResetTimer() 82 83 b.RunParallel(func(pb *testing.PB) { 84 for pb.Next() { 85 fmt.Fprintln(ioutil.Discard, short) 86 } 87 }) 88 }