From e67f943a6d20018f13afa8e06a0ea5bb5fb7e678 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Thu, 6 Mar 2025 11:25:00 +0300 Subject: [PATCH] [#1619] logger: Update benchmark Signed-off-by: Anton Nikiforov --- pkg/util/logger/logger_test.go | 78 ++++++++++++++++++++++-- pkg/util/logger/logger_test.result | 96 ++++++++++++++++++++++++++---- 2 files changed, 158 insertions(+), 16 deletions(-) diff --git a/pkg/util/logger/logger_test.go b/pkg/util/logger/logger_test.go index ae921751a..5ab67b9ed 100644 --- a/pkg/util/logger/logger_test.go +++ b/pkg/util/logger/logger_test.go @@ -7,18 +7,88 @@ import ( "github.com/stretchr/testify/require" ) -func BenchmarkLogger(b *testing.B) { +func BenchmarkLoggerMain(b *testing.B) { ctx := context.Background() - prm := Prm{} require.NoError(b, prm.SetLevelString("debug")) - + require.NoError(b, prm.SetAllowedTags([]string{"main: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 BenchmarkLoggerLevelLessTagAllowed(b *testing.B) { + ctx := context.Background() + prm := Prm{} + require.NoError(b, prm.SetLevelString("info")) + require.NoError(b, prm.SetAllowedTags([]string{"main: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 BenchmarkLoggerLevelGreaterTagAllowed(b *testing.B) { + ctx := context.Background() + prm := Prm{} + require.NoError(b, prm.SetLevelString("debug")) + require.NoError(b, prm.SetAllowedTags([]string{"main:info"})) + 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 BenchmarkLoggerLevelLessTagDisabled(b *testing.B) { + ctx := context.Background() + prm := Prm{} + require.NoError(b, prm.SetLevelString("info")) + require.NoError(b, prm.SetAllowedTags([]string{"morph: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 BenchmarkLoggerLevelGreaterTagDisabled(b *testing.B) { + ctx := context.Background() + prm := Prm{} + require.NoError(b, prm.SetLevelString("debug")) + require.NoError(b, prm.SetAllowedTags([]string{"morph:info"})) 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") diff --git a/pkg/util/logger/logger_test.result b/pkg/util/logger/logger_test.result index a2a9242d0..7c68e4d21 100644 --- a/pkg/util/logger/logger_test.result +++ b/pkg/util/logger/logger_test.result @@ -1,17 +1,89 @@ -warning: GOPATH set to GOROOT (/home/annikifa/workspace/go/go1.22.6/) has no effect +BenchmarkLoggerMain 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 518.1 ns/op 23 B/op 0 allocs/op - 10000 523.6 ns/op 23 B/op 0 allocs/op - 10000 526.7 ns/op 23 B/op 0 allocs/op - 10000 513.5 ns/op 22 B/op 0 allocs/op - 10000 520.5 ns/op 23 B/op 0 allocs/op - 10000 517.5 ns/op 23 B/op 0 allocs/op - 10000 517.6 ns/op 23 B/op 0 allocs/op - 10000 623.3 ns/op 23 B/op 0 allocs/op - 10000 517.7 ns/op 23 B/op 0 allocs/op - 10000 654.9 ns/op 23 B/op 0 allocs/op + 10000 557.8 ns/op 23 B/op 0 allocs/op + 10000 551.8 ns/op 23 B/op 0 allocs/op + 10000 569.9 ns/op 23 B/op 0 allocs/op + 10000 680.2 ns/op 22 B/op 0 allocs/op + 10000 679.1 ns/op 22 B/op 0 allocs/op + 10000 571.2 ns/op 23 B/op 0 allocs/op + 10000 559.4 ns/op 22 B/op 0 allocs/op + 10000 566.8 ns/op 23 B/op 0 allocs/op + 10000 542.5 ns/op 22 B/op 0 allocs/op + 10000 556.1 ns/op 23 B/op 0 allocs/op PASS -ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.065s +ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.070s + +BenchmarkLoggerLevelLessTagAllowed +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 551.8 ns/op 23 B/op 0 allocs/op + 10000 542.7 ns/op 23 B/op 0 allocs/op + 10000 567.0 ns/op 23 B/op 0 allocs/op + 10000 547.2 ns/op 22 B/op 0 allocs/op + 10000 542.9 ns/op 23 B/op 0 allocs/op + 10000 569.4 ns/op 22 B/op 0 allocs/op + 10000 563.3 ns/op 22 B/op 0 allocs/op + 10000 553.4 ns/op 23 B/op 0 allocs/op + 10000 550.0 ns/op 22 B/op 0 allocs/op + 10000 599.5 ns/op 23 B/op 0 allocs/op +PASS +ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.067s + +BenchmarkLoggerLevelGreaterTagAllowed +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.6 ns/op 17 B/op 0 allocs/op + 10000 418.6 ns/op 17 B/op 0 allocs/op + 10000 434.5 ns/op 17 B/op 0 allocs/op + 10000 495.0 ns/op 17 B/op 0 allocs/op + 10000 423.5 ns/op 17 B/op 0 allocs/op + 10000 426.1 ns/op 17 B/op 0 allocs/op + 10000 416.9 ns/op 17 B/op 0 allocs/op + 10000 435.2 ns/op 17 B/op 0 allocs/op + 10000 422.6 ns/op 17 B/op 0 allocs/op + 10000 416.1 ns/op 17 B/op 0 allocs/op +PASS +ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.055s + +BenchmarkLoggerLevelLessTagDisabled +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 +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.97 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.97 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.95 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 13.16 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 13.75 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 13.20 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 15.93 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.96 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.96 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelLessTagDisabled-8 10000 12.96 ns/op 0 B/op 0 allocs/op +PASS +ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.010s + +BenchmarkLoggerLevelGreaterTagDisabled +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 +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.71 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.72 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.71 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.71 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.71 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.70 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 13.20 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 12.71 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 13.45 ns/op 0 B/op 0 allocs/op +BenchmarkLoggerLevelGreaterTagDisabled-8 10000 13.18 ns/op 0 B/op 0 allocs/op +PASS +ok git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger 0.011s