Skip to content

Commit

Permalink
add phuslu/slog to speedup slog benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
phuslu committed May 12, 2024
1 parent 8b1e486 commit 08f6b76
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,41 @@ func BenchmarkSlogAny(b *testing.B) {
}
}

func BenchmarkSlogPhusDisabled(b *testing.B) {
logger := slog.New(phuslog.SlogNewJSONHandler(io.Discard, nil))
for i := 0; i < b.N; i++ {
logger.Debug(msg, "rate", "15", "low", 16, "high", 123.2)
}
}

func BenchmarkSlogPhusSimple(b *testing.B) {
logger := slog.New(phuslog.SlogNewJSONHandler(io.Discard, nil))
for i := 0; i < b.N; i++ {
logger.Info(msg, "rate", "15", "low", 16, "high", 123.2)
}
}

func BenchmarkSlogPhusPrintf(b *testing.B) {
slog.SetDefault(slog.New(phuslog.SlogNewJSONHandler(io.Discard, nil)))
for i := 0; i < b.N; i++ {
log.Printf("rate=%s low=%d high=%f msg=%s", "15", 16, 123.2, msg)
}
}

func BenchmarkSlogPhusCaller(b *testing.B) {
logger := slog.New(phuslog.SlogNewJSONHandler(io.Discard, &slog.HandlerOptions{AddSource: true}))
for i := 0; i < b.N; i++ {
logger.Info(msg, "rate", "15", "low", 16, "high", 123.2)
}
}

func BenchmarkSlogPhusAny(b *testing.B) {
logger := slog.New(phuslog.SlogNewJSONHandler(io.Discard, nil))
for i := 0; i < b.N; i++ {
logger.Info(msg, "rate", "15", "low", 16, "object", &obj)
}
}

func BenchmarkZapDisabled(b *testing.B) {
logger := zap.New(zapcore.NewCore(
zapcore.NewJSONEncoder(zap.NewProductionEncoderConfig()),
Expand Down

0 comments on commit 08f6b76

Please sign in to comment.