diff options
author | Lukas Macko <lmacko@cisco.com> | 2017-09-12 09:54:58 +0200 |
---|---|---|
committer | Lukas Macko <lmacko@cisco.com> | 2017-09-12 10:49:11 +0200 |
commit | 217383b613248c79b542623ec6c571591de113ce (patch) | |
tree | 35b2064a8b780e0b18a8ffba31757caa2ed3e10f /vendor/github.com/Sirupsen/logrus/logger_bench_test.go | |
parent | d07761baec9f09aef0b140ea46e38bd597dbdbbc (diff) |
Use Sirupsen/logrus with uppercase
Change-Id: I2f8870c52f64eb56deb44e4a807867b3ef0a0b76
Signed-off-by: Lukas Macko <lmacko@cisco.com>
Diffstat (limited to 'vendor/github.com/Sirupsen/logrus/logger_bench_test.go')
-rw-r--r-- | vendor/github.com/Sirupsen/logrus/logger_bench_test.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/github.com/Sirupsen/logrus/logger_bench_test.go b/vendor/github.com/Sirupsen/logrus/logger_bench_test.go new file mode 100644 index 0000000..dd23a35 --- /dev/null +++ b/vendor/github.com/Sirupsen/logrus/logger_bench_test.go @@ -0,0 +1,61 @@ +package logrus + +import ( + "os" + "testing" +) + +// smallFields is a small size data set for benchmarking +var loggerFields = Fields{ + "foo": "bar", + "baz": "qux", + "one": "two", + "three": "four", +} + +func BenchmarkDummyLogger(b *testing.B) { + nullf, err := os.OpenFile("/dev/null", os.O_WRONLY, 0666) + if err != nil { + b.Fatalf("%v", err) + } + defer nullf.Close() + doLoggerBenchmark(b, nullf, &TextFormatter{DisableColors: true}, smallFields) +} + +func BenchmarkDummyLoggerNoLock(b *testing.B) { + nullf, err := os.OpenFile("/dev/null", os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + b.Fatalf("%v", err) + } + defer nullf.Close() + doLoggerBenchmarkNoLock(b, nullf, &TextFormatter{DisableColors: true}, smallFields) +} + +func doLoggerBenchmark(b *testing.B, out *os.File, formatter Formatter, fields Fields) { + logger := Logger{ + Out: out, + Level: InfoLevel, + Formatter: formatter, + } + entry := logger.WithFields(fields) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + entry.Info("aaa") + } + }) +} + +func doLoggerBenchmarkNoLock(b *testing.B, out *os.File, formatter Formatter, fields Fields) { + logger := Logger{ + Out: out, + Level: InfoLevel, + Formatter: formatter, + } + logger.SetNoLock() + entry := logger.WithFields(fields) + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + entry.Info("aaa") + } + }) +} |