All checks were successful
DCO action / DCO (pull_request) Successful in 40s
Vulncheck / Vulncheck (pull_request) Successful in 1m0s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m28s
Build / Build Components (pull_request) Successful in 1m57s
Tests and linters / gopls check (pull_request) Successful in 3m42s
Tests and linters / Run gofumpt (pull_request) Successful in 4m55s
Tests and linters / Staticcheck (pull_request) Successful in 5m53s
Tests and linters / Lint (pull_request) Successful in 6m3s
Tests and linters / Tests (pull_request) Successful in 6m1s
Tests and linters / Tests with -race (pull_request) Successful in 6m46s
Change-Id: I04121a0550b3cdd8b8655fdeb2c5e0d062a96404 Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
78 lines
1.7 KiB
Go
78 lines
1.7 KiB
Go
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")
|
|
}
|
|
}
|
|
|
|
func BenchmarkLoggerLevelLess(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("info"))
|
|
require.NoError(b, prm.SetTags([][]string{{"main", "debug"}, {"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 BenchmarkLoggerLevelGreater(b *testing.B) {
|
|
ctx := context.Background()
|
|
prm := Prm{}
|
|
require.NoError(b, prm.SetLevelString("debug"))
|
|
require.NoError(b, prm.SetTags([][]string{{"main", "error"}, {"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")
|
|
}
|
|
}
|