Created
February 20, 2016 03:08
-
-
Save ChrisHines/5c32bd11dd16db713776 to your computer and use it in GitHub Desktop.
Simple benchmark for three logging packages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"io/ioutil" | |
"testing" | |
"github.com/Sirupsen/logrus" | |
"github.com/go-kit/kit/log" | |
"gopkg.in/inconshreveable/log15.v2" | |
) | |
func BenchmarkGokitLogfmt(b *testing.B) { | |
lg := log.NewLogfmtLogger(ioutil.Discard) | |
for i := 0; i < b.N; i++ { | |
lg.Log("lvl", "info", "msg", "test message", "k1", "v1", "k2", "v2", "k3", "v3") | |
} | |
} | |
func BenchmarkLog15Logfmt(b *testing.B) { | |
lg := log15.New() | |
lg.SetHandler(log15.StreamHandler(ioutil.Discard, log15.LogfmtFormat())) | |
for i := 0; i < b.N; i++ { | |
lg.Info("test message", "k1", "v1", "k2", "v2", "k3", "v3") | |
} | |
} | |
func BenchmarkLogrusLogfmt(b *testing.B) { | |
lg := logrus.New() | |
lg.Out = ioutil.Discard | |
for i := 0; i < b.N; i++ { | |
lg.WithFields(logrus.Fields{ | |
"k1": "v1", "k2": "v2", "k3": "v3", | |
}).Info("test message") | |
} | |
} |
Another performance improvement in GokitLogfmt: Less memory allocation when handling values that require quoting.
name time/op
GokitLogfmt-4 3.41µs ± 3%
Log15Logfmt-4 18.4µs ± 4%
LogrusLogfmt-4 12.8µs ± 1%
name alloc/op
GokitLogfmt-4 320B ± 0%
Log15Logfmt-4 1.96kB ± 0%
LogrusLogfmt-4 1.62kB ± 0%
name allocs/op
GokitLogfmt-4 11.0 ± 0%
Log15Logfmt-4 45.0 ± 0%
LogrusLogfmt-4 27.0 ± 0%
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
GokitLogfmt has improved since the first posting. Here are updated benchmarks for Go 1.6.2 on the same machine as before with the latest versions of all the packages. This time using benchstat with 10 runs.