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") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another performance improvement in GokitLogfmt: Less memory allocation when handling values that require quoting.