|
7 | 7 | using OpenTelemetry.Logs;
|
8 | 8 |
|
9 | 9 | /*
|
10 |
| -BenchmarkDotNet v0.13.10, Windows 11 (10.0.23424.1000) |
11 |
| -Intel Core i7-9700 CPU 3.00GHz, 1 CPU, 8 logical and 8 physical cores |
12 |
| -.NET SDK 8.0.100 |
13 |
| - [Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 |
14 |
| - DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 |
15 |
| -
|
16 |
| -
|
17 |
| -| Method | Mean | Error | StdDev | Median | Gen0 | Allocated | |
18 |
| -|--------------------------------------- |-----------:|----------:|----------:|-----------:|-------:|----------:| |
19 |
| -| NoListener | 44.633 ns | 0.8442 ns | 1.9733 ns | 43.683 ns | 0.0102 | 64 B | |
20 |
| -| NoListenerWithLoggerMessageGenerator | 1.880 ns | 0.0141 ns | 0.0125 ns | 1.879 ns | - | - | |
21 |
| -| OneProcessor | 126.857 ns | 1.1861 ns | 1.0514 ns | 126.730 ns | 0.0165 | 104 B | |
22 |
| -| OneProcessorWithLoggerMessageGenerator | 112.677 ns | 1.0021 ns | 0.8884 ns | 112.605 ns | 0.0063 | 40 B | |
23 |
| -| TwoProcessors | 129.967 ns | 0.8315 ns | 0.7371 ns | 129.850 ns | 0.0165 | 104 B | |
24 |
| -| ThreeProcessors | 130.117 ns | 1.1359 ns | 1.0626 ns | 129.991 ns | 0.0165 | 104 B | |
| 10 | +BenchmarkDotNet v0.13.10, Windows 11 (10.0.22621.3007/22H2/2022Update/SunValley2) |
| 11 | +11th Gen Intel Core i7-1185G7 3.00GHz, 1 CPU, 8 logical and 4 physical cores |
| 12 | +.NET SDK 8.0.101 |
| 13 | + [Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2 |
| 14 | + DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2 |
| 15 | +
|
| 16 | +
|
| 17 | +| Method | Mean | Error | StdDev | Gen0 | Allocated | |
| 18 | +|------------------------------ |-----------:|----------:|----------:|-------:|----------:| |
| 19 | +| NoListenerStringInterpolation | 124.458 ns | 2.5188 ns | 2.2329 ns | 0.0114 | 72 B | |
| 20 | +| NoListenerExtensionMethod | 36.326 ns | 0.2916 ns | 0.2435 ns | 0.0102 | 64 B | |
| 21 | +| NoListener | 1.375 ns | 0.0586 ns | 0.0896 ns | - | - | |
| 22 | +| OneProcessor | 98.133 ns | 1.8805 ns | 1.5703 ns | 0.0063 | 40 B | |
| 23 | +| TwoProcessors | 105.414 ns | 0.4610 ns | 0.3850 ns | 0.0063 | 40 B | |
| 24 | +| ThreeProcessors | 102.023 ns | 1.4187 ns | 1.1847 ns | 0.0063 | 40 B | |
25 | 25 | */
|
26 | 26 |
|
27 | 27 | namespace Benchmarks.Logs;
|
28 | 28 |
|
29 | 29 | public class LogBenchmarks
|
30 | 30 | {
|
| 31 | + private const double FoodPrice = 2.99; |
| 32 | + private static readonly string FoodName = "tomato"; |
| 33 | + |
31 | 34 | private readonly ILogger loggerWithNoListener;
|
32 | 35 | private readonly ILogger loggerWithOneProcessor;
|
33 | 36 | private readonly ILogger loggerWithTwoProcessors;
|
@@ -64,39 +67,39 @@ public LogBenchmarks()
|
64 | 67 | }
|
65 | 68 |
|
66 | 69 | [Benchmark]
|
67 |
| - public void NoListener() |
| 70 | + public void NoListenerStringInterpolation() |
68 | 71 | {
|
69 |
| - this.loggerWithNoListener.LogInformation("Hello from {name} {price}.", "tomato", 2.99); |
| 72 | + this.loggerWithNoListener.LogInformation($"Hello from {FoodName} {FoodPrice}."); |
70 | 73 | }
|
71 | 74 |
|
72 | 75 | [Benchmark]
|
73 |
| - public void NoListenerWithLoggerMessageGenerator() |
| 76 | + public void NoListenerExtensionMethod() |
74 | 77 | {
|
75 |
| - Food.SayHello(this.loggerWithNoListener, "tomato", 2.99); |
| 78 | + this.loggerWithNoListener.LogInformation("Hello from {name} {price}.", FoodName, FoodPrice); |
76 | 79 | }
|
77 | 80 |
|
78 | 81 | [Benchmark]
|
79 |
| - public void OneProcessor() |
| 82 | + public void NoListener() |
80 | 83 | {
|
81 |
| - this.loggerWithOneProcessor.LogInformation("Hello from {name} {price}.", "tomato", 2.99); |
| 84 | + Food.SayHello(this.loggerWithNoListener, FoodName, FoodPrice); |
82 | 85 | }
|
83 | 86 |
|
84 | 87 | [Benchmark]
|
85 |
| - public void OneProcessorWithLoggerMessageGenerator() |
| 88 | + public void OneProcessor() |
86 | 89 | {
|
87 |
| - Food.SayHello(this.loggerWithOneProcessor, "tomato", 2.99); |
| 90 | + Food.SayHello(this.loggerWithOneProcessor, FoodName, FoodPrice); |
88 | 91 | }
|
89 | 92 |
|
90 | 93 | [Benchmark]
|
91 | 94 | public void TwoProcessors()
|
92 | 95 | {
|
93 |
| - this.loggerWithTwoProcessors.LogInformation("Hello from {name} {price}.", "tomato", 2.99); |
| 96 | + Food.SayHello(this.loggerWithTwoProcessors, FoodName, FoodPrice); |
94 | 97 | }
|
95 | 98 |
|
96 | 99 | [Benchmark]
|
97 | 100 | public void ThreeProcessors()
|
98 | 101 | {
|
99 |
| - this.loggerWithThreeProcessors.LogInformation("Hello from {name} {price}.", "tomato", 2.99); |
| 102 | + Food.SayHello(this.loggerWithThreeProcessors, FoodName, FoodPrice); |
100 | 103 | }
|
101 | 104 |
|
102 | 105 | internal class DummyLogProcessor : BaseProcessor<LogRecord>
|
|
0 commit comments