Skip to content

feat: add klogr to the list of benchmarks #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- **github.com/sirupsen/logrus**: [logrusr](https://github.com/bombsimon/logrusr)
- **go.uber.org/zap**: [zapr](https://github.com/go-logr/zapr)
- **github.com/rs/zerolog**: [zerologr](https://github.com/go-logr/zerologr)
- **k8s.io/klog/v2**: [klogr](https://github.com/kubernetes/klog/tree/main/klogr)

## Benchmark

Expand Down
45 changes: 44 additions & 1 deletion benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ import (
"github.com/rs/zerolog"
"github.com/sirupsen/logrus"
"go.uber.org/zap"
"k8s.io/klog/v2/klogr"
)

func init() {
os.Stderr, _ = os.Open("/dev/null")

// stdr
stdr.SetVerbosity(1)
// globr
// glogr / klogr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually bump verbosity for klog because klog.InitFlags wasn't called. It cannot be called because the glog and klog would conflict because both would try to register the same flag.

I don't think it matters because we log at V(0) (enabled by default) and V(9) (disabled by default).

Does it matter for glog? If not, then this whole flag.Set("v", "1") should get removed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't use glog much.

flag.Set("v", "1")
flag.Set("logtostderr", "true")
// zerologr
Expand Down Expand Up @@ -447,3 +448,45 @@ func BenchmarkZerologrWithCallDepth(b *testing.B) {
var log logr.Logger = zerologrLogger()
doWithCallDepth(b, log)
}

// klog

func BenchmarkKlogrInfoOneArg(b *testing.B) {
var log logr.Logger = klogr.New()
doInfoOneArg(b, log)
}

func BenchmarkKlogrInfoSeveralArgs(b *testing.B) {
var log logr.Logger = klogr.New()
doInfoSeveralArgs(b, log)
}

func BenchmarkKlogrV0Info(b *testing.B) {
var log logr.Logger = klogr.New()
doV0Info(b, log)
}

func BenchmarkKlogrV9Info(b *testing.B) {
var log logr.Logger = klogr.New()
doV9Info(b, log)
}

func BenchmarkKlogrError(b *testing.B) {
var log logr.Logger = klogr.New()
doError(b, log)
}

func BenchmarkKlogrWithValues(b *testing.B) {
var log logr.Logger = klogr.New()
doWithValues(b, log)
}

func BenchmarkKlogrWithName(b *testing.B) {
var log logr.Logger = klogr.New()
doWithName(b, log)
}

func BenchmarkKlogrWithCallDepth(b *testing.B) {
var log logr.Logger = klogr.New()
doWithCallDepth(b, log)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ require (
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect
k8s.io/klog/v2 v2.80.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4=
k8s.io/klog/v2 v2.80.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=