Updated logging benchmarks to include source generation (#2800)
This commit is contained in:
parent
110b5c267f
commit
90146f84f2
|
|
@ -0,0 +1,30 @@
|
|||
// <copyright file="Food.cs" company="OpenTelemetry Authors">
|
||||
// Copyright The OpenTelemetry Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// </copyright>
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Benchmarks.Logs
|
||||
{
|
||||
public static partial class Food
|
||||
{
|
||||
[LoggerMessage(
|
||||
EventId = 0,
|
||||
Level = LogLevel.Information,
|
||||
Message = "Hello from {food} {price}.")]
|
||||
public static partial void SayHello(
|
||||
ILogger logger, string food, double price);
|
||||
}
|
||||
}
|
||||
|
|
@ -19,6 +19,26 @@ using Microsoft.Extensions.Logging;
|
|||
using OpenTelemetry;
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
/*
|
||||
// * Summary *
|
||||
|
||||
BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1466 (21H2)
|
||||
Intel Core i7-4790 CPU 3.60GHz (Haswell), 1 CPU, 8 logical and 4 physical cores
|
||||
.NET SDK=6.0.101
|
||||
[Host] : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
|
||||
DefaultJob : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT
|
||||
|
||||
|
||||
| Method | Mean | Error | StdDev | Gen 0 | Allocated |
|
||||
|--------------------------------------- |-----------:|----------:|----------:|-------:|----------:|
|
||||
| NoListener | 72.365 ns | 0.9425 ns | 0.8817 ns | 0.0153 | 64 B |
|
||||
| NoListenerWithLoggerMessageGenerator | 4.769 ns | 0.0161 ns | 0.0142 ns | - | - |
|
||||
| OneProcessor | 168.330 ns | 0.6198 ns | 0.5494 ns | 0.0553 | 232 B |
|
||||
| OneProcessorWithLoggerMessageGenerator | 142.898 ns | 0.5233 ns | 0.4086 ns | 0.0401 | 168 B |
|
||||
| TwoProcessors | 173.727 ns | 0.5978 ns | 0.4992 ns | 0.0553 | 232 B |
|
||||
| ThreeProcessors | 174.295 ns | 0.7697 ns | 0.7200 ns | 0.0553 | 232 B |
|
||||
*/
|
||||
|
||||
namespace Benchmarks.Logs
|
||||
{
|
||||
[MemoryDiagnoser]
|
||||
|
|
@ -62,25 +82,37 @@ namespace Benchmarks.Logs
|
|||
[Benchmark]
|
||||
public void NoListener()
|
||||
{
|
||||
this.loggerWithNoListener.LogInformation("Hello, World!");
|
||||
this.loggerWithNoListener.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void NoListenerWithLoggerMessageGenerator()
|
||||
{
|
||||
Food.SayHello(this.loggerWithNoListener, "tomato", 2.99);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void OneProcessor()
|
||||
{
|
||||
this.loggerWithOneProcessor.LogInformation("Hello, World!");
|
||||
this.loggerWithOneProcessor.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void OneProcessorWithLoggerMessageGenerator()
|
||||
{
|
||||
Food.SayHello(this.loggerWithOneProcessor, "tomato", 2.99);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void TwoProcessors()
|
||||
{
|
||||
this.loggerWithTwoProcessors.LogInformation("Hello, World!");
|
||||
this.loggerWithTwoProcessors.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public void ThreeProcessors()
|
||||
{
|
||||
this.loggerWithThreeProcessors.LogInformation("Hello, World!");
|
||||
this.loggerWithThreeProcessors.LogInformation("Hello from {name} {price}.", "tomato", 2.99);
|
||||
}
|
||||
|
||||
internal class DummyLogProcessor : BaseProcessor<LogRecord>
|
||||
|
|
|
|||
Loading…
Reference in New Issue