diff options
| author | Felix Hanley <felix@userspace.com.au> | 2019-05-02 05:31:59 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2019-05-02 05:31:59 +0000 |
| commit | 20ecdb3867bb0a88714c1768ca078c8b98df3708 (patch) | |
| tree | 16f7382d9b18a867ddfcf15d8d6f7864c5631e98 | |
| parent | 8ab19e560484637675425fc22d10307d7d9fca2b (diff) | |
| download | logger-20ecdb3867bb0a88714c1768ca078c8b98df3708.tar.gz logger-20ecdb3867bb0a88714c1768ca078c8b98df3708.tar.bz2 | |
Add some simple comparisons
| -rw-r--r-- | README.md | 13 | ||||
| -rw-r--r-- | comparison_test.go | 47 |
2 files changed, 52 insertions, 8 deletions
@@ -60,12 +60,9 @@ msgLog.Error("failed to process message") ## Comparison ``` -goos: darwin -goarch: amd64 -pkg: src.userspace.com.au/felix/logger -BenchmarkLocal-12 2000000 660 ns/op -BenchmarkStdlib-12 5000000 289 ns/op -BenchmarkLogrus-12 1000000 1744 ns/op -BenchmarkFieldsLocal-12 1000000 1029 ns/op -BenchmarkFieldsLogrus-12 1000000 2058 ns/op +BenchmarkCoreLogger-12 5000000 288 ns/op +BenchmarkLocal-12 2000000 654 ns/op +BenchmarkLogrus-12 1000000 1738 ns/op +BenchmarkFieldsLocal-12 1000000 1024 ns/op +BenchmarkFieldsLogrus-12 1000000 2061 ns/op ``` diff --git a/comparison_test.go b/comparison_test.go new file mode 100644 index 0000000..86a26fd --- /dev/null +++ b/comparison_test.go @@ -0,0 +1,47 @@ +package logger + +import ( + "io/ioutil" + "log" + "testing" + + logrus "github.com/sirupsen/logrus" +) + +func BenchmarkCoreLogger(b *testing.B) { + log.SetOutput(ioutil.Discard) + for n := 0; n < b.N; n++ { + log.Print("Some text") + } +} + +func BenchmarkLocal(b *testing.B) { + l, _ := New(SetOutput(ioutil.Discard)) + for n := 0; n < b.N; n++ { + l.Error("Some text") + } +} + +func BenchmarkLogrus(b *testing.B) { + logrus.SetOutput(ioutil.Discard) + for n := 0; n < b.N; n++ { + logrus.Error("Some text") + } +} + +func BenchmarkFieldsLocal(b *testing.B) { + l, _ := New(SetOutput(ioutil.Discard)) + l.SetField("key", "value") + l.SetField("one", "two") + for n := 0; n < b.N; n++ { + l.Error("Some text") + } +} + +func BenchmarkFieldsLogrus(b *testing.B) { + logrus.SetOutput(ioutil.Discard) + l := logrus.WithFields(logrus.Fields{"key": "value", "one": "two"}) + for n := 0; n < b.N; n++ { + l.Error("Some text") + } +} |
