From 5be705cbad60b300cc5c360d4c46169466bdf2dd Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Thu, 27 Jun 2024 14:34:05 -0700 Subject: [PATCH] Add benchmarks --- processors/minsev/minsev_test.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/processors/minsev/minsev_test.go b/processors/minsev/minsev_test.go index 28662250dd1..645895a54ac 100644 --- a/processors/minsev/minsev_test.go +++ b/processors/minsev/minsev_test.go @@ -165,3 +165,27 @@ func TestLogProcessorNilDownstream(t *testing.T) { assert.NoError(t, p.Shutdown(ctx)) }) } + +func BenchmarkLogProcessor(b *testing.B) { + rPtr := new(log.Record) + rPtr.SetSeverity(api.SeverityTrace) + ctx, r := context.Background(), *rPtr + + run := func(p log.Processor) func(b *testing.B) { + return func(b *testing.B) { + var err error + var enabled bool + b.ReportAllocs() + for n := 0; n < b.N; n++ { + enabled = p.Enabled(ctx, r) + err = p.OnEmit(ctx, r) + } + + _, _ = err, enabled + } + } + + b.Run("Base", run(defaultProcessor)) + b.Run("Enabled", run(NewLogProcessor(nil, api.SeverityTrace))) + b.Run("Disabled", run(NewLogProcessor(nil, api.SeverityDebug))) +}