Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
muir committed Aug 12, 2022
1 parent 6cf89da commit 0c16adb
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 360 deletions.
33 changes: 0 additions & 33 deletions .github/workflows/benchmark.yml

This file was deleted.

11 changes: 11 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ all: $(ZZZGENERATED)

test: $(ZZZGENERATED)
go generate ./...
go test -v ./xopjson/... -run TestASingleLine
go test -v ./xopjson/... -run TestNoBuffer
go test ./...
go test -v ./xopjson/...

${GOBIN}/gofumpt:;
go install mvdan.cc/gofumpt@latest
Expand Down
287 changes: 11 additions & 276 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,280 +324,15 @@ need to be [registered](https://opencensus.io/tag/key/).

### Performance

The performance of Xop is good enough. See the benchmark results
from the last run at [logbench](https://github.com/muir/logbench/actions).

```go
// go test -v -cpu=4 -run=none -bench=. -benchtime=10s -benchmem bmark_test.go

package xop_test

import (
"io/ioutil"
"testing"
"time"

"github.com/francoispqt/onelog"
"github.com/muir/xop-go"
"github.com/muir/xop-go/xopbytes"
"github.com/muir/xop-go/xopconst"
"github.com/muir/xop-go/xopjson"
"github.com/phuslu/log"
"github.com/rs/zerolog"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

var msg = "The quick brown fox jumps over the lazy dog"
var obj = struct {
Rate string
Low int
High float32
}{"15", 16, 123.2}

func BenchmarkDisableXop(b *testing.B) {
logger := xop.NewSeed(xop.WithBase(
xopjson.New(
xopbytes.WriteToIOWriter(ioutil.Discard),
xopjson.WithEpochTime(time.Nanosecond),
xopjson.WithDurationFormat(xopjson.AsNanos),
xopjson.WithSpanTags(xopjson.SpanIDTagOption),
xopjson.WithAttributesObject(false)))).
Request("disable")
for i := 0; i < b.N; i++ {
logger.Debug().String("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
logger.Done()
}

func BenchmarkNormalXop(b *testing.B) {
logger := xop.NewSeed(xop.WithBase(
xopjson.New(
xopbytes.WriteToIOWriter(ioutil.Discard),
xopjson.WithEpochTime(time.Nanosecond),
xopjson.WithDurationFormat(xopjson.AsNanos),
xopjson.WithSpanTags(xopjson.SpanIDTagOption),
xopjson.WithAttributesObject(false)))).
Request("disable")
for i := 0; i < b.N; i++ {
logger.Info().String("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
logger.Done()
}

func BenchmarkInterfaceXop(b *testing.B) {
logger := xop.NewSeed(xop.WithBase(
xopjson.New(
xopbytes.WriteToIOWriter(ioutil.Discard),
xopjson.WithEpochTime(time.Nanosecond),
xopjson.WithDurationFormat(xopjson.AsNanos),
xopjson.WithSpanTags(xopjson.SpanIDTagOption),
xopjson.WithAttributesObject(false)))).
Request("disable")
for i := 0; i < b.N; i++ {
logger.Info().Any("object", &obj).Msg(msg)
}
logger.Done()
}

func BenchmarkPrintfXop(b *testing.B) {
logger := xop.NewSeed(xop.WithBase(
xopjson.New(
xopbytes.WriteToIOWriter(ioutil.Discard),
xopjson.WithEpochTime(time.Nanosecond),
xopjson.WithDurationFormat(xopjson.AsNanos),
xopjson.WithSpanTags(xopjson.SpanIDTagOption),
xopjson.WithAttributesObject(false)))).
Request("disable")
for i := 0; i < b.N; i++ {
logger.Info().Msgf("rate=%s low=%d high=%f msg=%s", "15", 16, 123.2, msg)
}
logger.Done()
}

func BenchmarkCallerXop(b *testing.B) {
logger := xop.NewSeed(xop.WithBase(
xopjson.New(
xopbytes.WriteToIOWriter(ioutil.Discard),
xopjson.WithEpochTime(time.Nanosecond),
xopjson.WithDurationFormat(xopjson.AsNanos),
xopjson.WithSpanTags(xopjson.SpanIDTagOption),
xopjson.WithAttributesObject(false)))).
Request("disable").
Sub().
StackFrames(xopconst.InfoLevel, 1).
Log()
for i := 0; i < b.N; i++ {
logger.Info().String("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
logger.Done()
}

func BenchmarkDisableZap(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(ioutil.Discard),
zapcore.InfoLevel,
))
for i := 0; i < b.N; i++ {
logger.Debug(msg, zap.String("rate", "15"), zap.Int("low", 16), zap.Float32("high", 123.2))
}
}

func BenchmarkNormalZap(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(ioutil.Discard),
zapcore.InfoLevel,
))
for i := 0; i < b.N; i++ {
logger.Info(msg, zap.String("rate", "15"), zap.Int("low", 16), zap.Float32("high", 123.2))
}
}

func BenchmarkInterfaceZap(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(ioutil.Discard),
zapcore.InfoLevel,
)).Sugar()
for i := 0; i < b.N; i++ {
logger.Infow(msg, "object", &obj)
}
}

func BenchmarkPrintfZap(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(ioutil.Discard),
zapcore.InfoLevel,
)).Sugar()
for i := 0; i < b.N; i++ {
logger.Infof("rate=%s low=%d high=%f msg=%s", "15", 16, 123.2, msg)
}
}

func BenchmarkCallerZap(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
zapcore.AddSync(ioutil.Discard),
zapcore.InfoLevel),
zap.AddCaller(),
)
for i := 0; i < b.N; i++ {
logger.Info(msg, zap.String("rate", "15"), zap.Int("low", 16), zap.Float32("high", 123.2))
}
}

func BenchmarkDisableZeroLog(b *testing.B) {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
logger := zerolog.New(ioutil.Discard).With().Timestamp().Logger()
for i := 0; i < b.N; i++ {
logger.Debug().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}

func BenchmarkNormalZeroLog(b *testing.B) {
logger := zerolog.New(ioutil.Discard).With().Timestamp().Logger()
for i := 0; i < b.N; i++ {
logger.Info().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}

func BenchmarkInterfaceZeroLog(b *testing.B) {
logger := zerolog.New(ioutil.Discard).With().Timestamp().Logger()
for i := 0; i < b.N; i++ {
logger.Info().Interface("object", &obj).Msg(msg)
}
}

func BenchmarkPrintfZeroLog(b *testing.B) {
logger := zerolog.New(ioutil.Discard).With().Timestamp().Logger()
for i := 0; i < b.N; i++ {
logger.Info().Msgf("rate=%s low=%d high=%f msg=%s", "15", 16, 123.2, msg)
}
}

func BenchmarkCallerZeroLog(b *testing.B) {
logger := zerolog.New(ioutil.Discard).With().Caller().Timestamp().Logger()
for i := 0; i < b.N; i++ {
logger.Info().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}

func BenchmarkDisableOneLog(b *testing.B) {
logger := onelog.New(ioutil.Discard, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL)
for i := 0; i < b.N; i++ {
logger.DebugWithFields(msg, func(e onelog.Entry) {
e.String("rate", "15")
e.Int("low", 16)
e.Float("high", 123.2)
})
}
}

func BenchmarkDisableOneLogChain(b *testing.B) {
logger := onelog.New(ioutil.Discard, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL)
for i := 0; i < b.N; i++ {
logger.DebugWith(msg).String("rate", "15").Int("low", 16).Float("high", 123.2).Write()
}
}

func BenchmarkNormalOneLog(b *testing.B) {
logger := onelog.New(ioutil.Discard, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL)
for i := 0; i < b.N; i++ {
logger.InfoWithFields(msg, func(e onelog.Entry) {
e.String("rate", "15")
e.Int("low", 16)
e.Float("high", 123.2)
})
}
}

func BenchmarkNormalOneLogChain(b *testing.B) {
logger := onelog.New(ioutil.Discard, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL)
for i := 0; i < b.N; i++ {
logger.InfoWith(msg).String("rate", "15").Int("low", 16).Float("high", 123.2).Write()
}
}

func BenchmarkInterfaceOneLogChain(b *testing.B) {
logger := onelog.New(ioutil.Discard, onelog.INFO|onelog.WARN|onelog.ERROR|onelog.FATAL)
for i := 0; i < b.N; i++ {
logger.InfoWith(msg).Any("object", &obj).Write()
}
}

func BenchmarkDisablePhusLog(b *testing.B) {
logger := log.Logger{Level: log.InfoLevel, Writer: log.IOWriter{ioutil.Discard}}
for i := 0; i < b.N; i++ {
logger.Debug().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}

func BenchmarkNormalPhusLog(b *testing.B) {
logger := log.Logger{Writer: log.IOWriter{ioutil.Discard}}
for i := 0; i < b.N; i++ {
logger.Info().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}

func BenchmarkInterfacePhusLog(b *testing.B) {
logger := log.Logger{Writer: log.IOWriter{ioutil.Discard}}
for i := 0; i < b.N; i++ {
logger.Info().Interface("object", &obj).Msg(msg)
}
}

func BenchmarkPrintfPhusLog(b *testing.B) {
logger := log.Logger{Writer: log.IOWriter{ioutil.Discard}}
for i := 0; i < b.N; i++ {
logger.Info().Msgf("rate=%s low=%d high=%f msg=%s", "15", 16, 123.2, msg)
}
}

func BenchmarkCallerPhusLog(b *testing.B) {
logger := log.Logger{Caller: 1, Writer: log.IOWriter{ioutil.Discard}}
for i := 0; i < b.N; i++ {
logger.Info().Str("rate", "15").Int("low", 16).Float32("high", 123.2).Msg(msg)
}
}
```
In general: faster than
[zap](https://github.com/uber-go/zap);
about the same as
[zerolog](https://github.com/rs/zerolog);
but not as quick as
[onelog](https://github.com/francoispqt/onelog) or
[phuslog](https://github.com/phuslu/log).

Xop has a much richer feature set than onelog or phuslog.
Loading

0 comments on commit 0c16adb

Please sign in to comment.