[#1619] logger: Add benchmark

Change-Id: I49e90e8a3689a755755afd0638b327a6b1884795
Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2025-02-04 09:11:36 +03:00
parent af40b267e4
commit dfdf2a9f58
2 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,42 @@
package logger
import (
"context"
"testing"
"github.com/stretchr/testify/require"
)
func BenchmarkLoggerDebug(b *testing.B) {
ctx := context.Background()
prm := Prm{}
require.NoError(b, prm.SetLevelString("debug"))
logger, err := NewLogger(prm)
require.NoError(b, err)
b.ResetTimer()
b.ReportAllocs()
for range b.N {
logger.Debug(ctx, "test debug")
logger.Info(ctx, "test info")
logger.Warn(ctx, "test warn")
logger.Error(ctx, "test error")
}
}
func BenchmarkLoggerError(b *testing.B) {
ctx := context.Background()
prm := Prm{}
require.NoError(b, prm.SetLevelString("error"))
logger, err := NewLogger(prm)
require.NoError(b, err)
b.ResetTimer()
b.ReportAllocs()
for range b.N {
logger.Debug(ctx, "test debug")
logger.Info(ctx, "test info")
logger.Warn(ctx, "test warn")
logger.Error(ctx, "test error")
}
}

View file

@ -0,0 +1,35 @@
BenchmarkLoggerDebug
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
10000 526.5 ns/op 22 B/op 0 allocs/op
10000 528.7 ns/op 23 B/op 0 allocs/op
10000 527.1 ns/op 22 B/op 0 allocs/op
10000 514.7 ns/op 22 B/op 0 allocs/op
10000 545.2 ns/op 23 B/op 0 allocs/op
10000 517.8 ns/op 23 B/op 0 allocs/op
10000 518.0 ns/op 23 B/op 0 allocs/op
10000 559.1 ns/op 23 B/op 0 allocs/op
10000 644.6 ns/op 23 B/op 0 allocs/op
10000 521.0 ns/op 23 B/op 0 allocs/op
PASS
ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.065s
BenchmarkLoggerError
goos: linux
goarch: amd64
pkg: git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger
cpu: 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
10000 209.3 ns/op 6 B/op 0 allocs/op
10000 213.7 ns/op 6 B/op 0 allocs/op
10000 186.4 ns/op 6 B/op 0 allocs/op
10000 193.0 ns/op 6 B/op 0 allocs/op
10000 181.0 ns/op 6 B/op 0 allocs/op
10000 177.6 ns/op 6 B/op 0 allocs/op
10000 181.7 ns/op 6 B/op 0 allocs/op
10000 183.8 ns/op 6 B/op 0 allocs/op
10000 190.2 ns/op 6 B/op 0 allocs/op
10000 185.0 ns/op 6 B/op 0 allocs/op
PASS
ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.030s