Skip to content

Commit

Permalink
log: improve Event benchmark to check redactability as well
Browse files Browse the repository at this point in the history
More CPU and a slightly different allocation profile, though the
allocations are largely driven by the arguments passed to `Eventf` and
they are trivial in this benchmark.

```
go test ./pkg/util/log -run - -bench BenchmarkEvent -benchtime 3s
goos: linux
goarch: amd64
pkg: github.com/cockroachdb/cockroach/pkg/util/log
cpu: AMD Ryzen 7 3800X 8-Core Processor
BenchmarkEventf_WithVerboseTraceSpan/redactable=false-16   759444  4903 ns/op  961 B/op   18 allocs/op
BenchmarkEventf_WithVerboseTraceSpan/redactable=true-16    561772  6831 ns/op  1081 B/op  16 allocs/op
```

Release note: None
  • Loading branch information
tbg authored and dhartunian committed Dec 8, 2021
1 parent 71ec9ce commit d76ae5d
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions pkg/util/log/clog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,15 +770,20 @@ func BenchmarkLogEntry_String(b *testing.B) {
}

func BenchmarkEventf_WithVerboseTraceSpan(b *testing.B) {
b.ReportAllocs()
tagbuf := logtags.SingleTagBuffer("hello", "there")
ctx := logtags.WithTags(context.Background(), tagbuf)
tracer := tracing.NewTracer()
ctx, sp := tracer.StartSpanCtx(ctx, "benchspan", tracing.WithForceRealSpan())
b.ResetTimer()
defer sp.Finish()
sp.SetVerbose(true)
for i := 0; i < b.N; i++ {
Eventf(ctx, "%s %s %s", "foo", "bar", "baz")
for _, redactable := range []bool{false, true} {
b.Run(fmt.Sprintf("redactable=%t", redactable), func(b *testing.B) {
b.ReportAllocs()
tagbuf := logtags.SingleTagBuffer("hello", "there")
ctx := logtags.WithTags(context.Background(), tagbuf)
tracer := tracing.NewTracer()
tracer.SetRedactable(redactable)
ctx, sp := tracer.StartSpanCtx(ctx, "benchspan", tracing.WithForceRealSpan())
defer sp.Finish()
b.ResetTimer()
sp.SetVerbose(true)
for i := 0; i < b.N; i++ {
Eventf(ctx, "%s %s %s", "foo", "bar", "baz")
}
})
}
}

0 comments on commit d76ae5d

Please sign in to comment.