Skip to content

Commit

Permalink
Exporter-Geneva add formatted message to benchmarks (#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
cijothomas authored Jul 7, 2022
1 parent 64a61b8 commit 361d704
Showing 1 changed file with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,16 @@
DefaultJob : .NET 6.0.6 (6.0.622.26707), X64 RyuJIT
| Method | Mean | Error | StdDev | Median | Gen 0 | Allocated |
|-------------------------- |-----------:|---------:|---------:|-----------:|-------:|----------:|
| LoggerWithMessageTemplate | 1,219.6 ns | 24.41 ns | 64.30 ns | 1,200.5 ns | 0.0858 | 360 B |
| LoggerWithDirectLoggerAPI | 1,043.6 ns | 19.02 ns | 17.79 ns | 1,050.5 ns | 0.0954 | 400 B |
| LoggerWithSourceGenerator | 1,138.1 ns | 22.62 ns | 28.60 ns | 1,134.1 ns | 0.0763 | 320 B |
| SerializeLogRecord | 845.5 ns | 10.18 ns | 9.52 ns | 845.5 ns | 0.0305 | 128 B |
| Method | IncludeFormattedMessage | Mean | Error | StdDev | Gen 0 | Allocated |
|-------------------------- |------------------------ |-----------:|---------:|---------:|-------:|----------:|
| LoggerWithMessageTemplate | False | 1,107.3 ns | 19.34 ns | 17.15 ns | 0.0858 | 360 B |
| LoggerWithDirectLoggerAPI | False | 1,027.4 ns | 8.92 ns | 7.91 ns | 0.1183 | 496 B |
| LoggerWithSourceGenerator | False | 1,081.5 ns | 4.53 ns | 4.24 ns | 0.0763 | 320 B |
| SerializeLogRecord | False | 825.1 ns | 6.88 ns | 5.74 ns | 0.0305 | 128 B |
| LoggerWithMessageTemplate | True | 1,123.3 ns | 2.24 ns | 1.87 ns | 0.0858 | 360 B |
| LoggerWithDirectLoggerAPI | True | 1,005.8 ns | 2.26 ns | 2.00 ns | 0.1183 | 496 B |
| LoggerWithSourceGenerator | True | 1,083.9 ns | 8.73 ns | 6.82 ns | 0.0763 | 320 B |
| SerializeLogRecord | True | 827.1 ns | 6.45 ns | 6.03 ns | 0.0305 | 128 B |
*/

namespace OpenTelemetry.Exporter.Geneva.Benchmark
Expand All @@ -46,6 +50,9 @@ public class LogExporterBenchmarks
private readonly GenevaLogExporter exporter;
private readonly LogRecord logRecord;

[Params(true, false)]
public bool IncludeFormattedMessage { get; set; }

public LogExporterBenchmarks()
{
// for total cost of logging + msgpack serialization
Expand All @@ -62,6 +69,8 @@ public LogExporterBenchmarks()
["cloud.roleVer"] = "9.0.15289.2",
};
});
loggerOptions.IncludeFormattedMessage = this.IncludeFormattedMessage;
}));

this.logger = this.loggerFactory.CreateLogger("TestLogger");
Expand Down Expand Up @@ -89,16 +98,18 @@ public void LoggerWithMessageTemplate()
[Benchmark]
public void LoggerWithDirectLoggerAPI()
{
var food = "artichoke";
var price = 3.99;
this.logger.Log(
logLevel: LogLevel.Information,
eventId: default,
state: new List<KeyValuePair<string, object>>()
{
new KeyValuePair<string, object>("food", "artichoke"),
new KeyValuePair<string, object>("price", 3.99),
new KeyValuePair<string, object>("food", food),
new KeyValuePair<string, object>("price", price),
},
exception: null,
formatter: (state, ex) => "Example formatted message.");
formatter: (state, ex) => $"Hello from {food} {price}.");
}

[Benchmark]
Expand Down

0 comments on commit 361d704

Please sign in to comment.