Skip to content

Instantly share code, notes, and snippets.

@ChrisHines
Created February 20, 2016 03:08
Show Gist options
  • Save ChrisHines/5c32bd11dd16db713776 to your computer and use it in GitHub Desktop.
Save ChrisHines/5c32bd11dd16db713776 to your computer and use it in GitHub Desktop.
Simple benchmark for three logging packages.
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")
}
}
@ChrisHines
Copy link
Author

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