Skip to content

Commit

Permalink
Add benchmark retrieving a new logger (open-telemetry#5548)
Browse files Browse the repository at this point in the history
This adds a benchmark to create a logger from a logger provider.

Related: open-telemetry#5054.

```
BenchmarkLoggerProviderLogger-10                         3145390               548.8 ns/op           330 B/op          1 allocs/op
```
  • Loading branch information
dmathieu authored Jun 27, 2024
1 parent 12f0db5 commit acb2471
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions sdk/log/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package log // import "go.opentelemetry.io/otel/sdk/log"

import (
"context"
"fmt"
"strconv"
"sync"
"testing"
Expand All @@ -17,6 +18,7 @@ import (
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/internal/global"
"go.opentelemetry.io/otel/log"
"go.opentelemetry.io/otel/log/noop"
"go.opentelemetry.io/otel/sdk/resource"
)
Expand Down Expand Up @@ -287,3 +289,22 @@ func TestLoggerProviderForceFlush(t *testing.T) {
assert.ErrorIs(t, p.ForceFlush(ctx), assert.AnError, "processor error not returned")
})
}

func BenchmarkLoggerProviderLogger(b *testing.B) {
p := NewLoggerProvider()
names := make([]string, b.N)
for i := 0; i < b.N; i++ {
names[i] = fmt.Sprintf("%d logger", i)
}

b.ResetTimer()
b.ReportAllocs()

loggers := make([]log.Logger, b.N)
for i := 0; i < b.N; i++ {
loggers[i] = p.Logger(names[i])
}

b.StopTimer()
loggers[0].Enabled(context.Background(), log.Record{})
}

0 comments on commit acb2471

Please sign in to comment.