forked from serilog/serilog
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request serilog#960 from nblumhardt/efficient-output-prope…
…rties Output template formatting harness
- Loading branch information
Showing
4 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/Serilog.PerformanceTests/MessageTemplateRenderingBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.PerformanceTests.Support; | ||
|
||
namespace Serilog.PerformanceTests | ||
{ | ||
/// <summary> | ||
/// Determines the cost of rendering a message template. | ||
/// </summary> | ||
public class MessageTemplateRenderingBenchmark | ||
{ | ||
static readonly LogEvent NoProperties = | ||
Some.InformationEvent("This template has no properties"); | ||
|
||
static readonly LogEvent VariedProperties = | ||
Some.InformationEvent("Processed {@Position} for {Task} in {Elapsed:000} ms", | ||
new { Latitude = 25, Longitude = 134 }, "Benchmark", 34); | ||
|
||
readonly StringWriter _output = new StringWriter(); | ||
|
||
[Setup] | ||
public void Setup() | ||
{ | ||
_output.GetStringBuilder().Length = 0; | ||
_output.GetStringBuilder().Capacity = 1024; // Only a few dozen chars actually needed here. | ||
} | ||
|
||
[Benchmark] | ||
public void TemplateWithNoProperties() | ||
{ | ||
NoProperties.MessageTemplate.Render(NoProperties.Properties, _output); | ||
} | ||
|
||
[Benchmark] | ||
public void TemplateWithVariedProperties() | ||
{ | ||
VariedProperties.MessageTemplate.Render(VariedProperties.Properties, _output); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
test/Serilog.PerformanceTests/OutputTemplateRenderingBenchmark.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using BenchmarkDotNet.Attributes; | ||
using System.Globalization; | ||
using System.IO; | ||
using Serilog.Events; | ||
using Serilog.Formatting.Display; | ||
using Serilog.PerformanceTests.Support; | ||
|
||
namespace Serilog.PerformanceTests | ||
{ | ||
/// <summary> | ||
/// Determines the cost of rendering an event out to one of the typical text targets, | ||
/// like the console or a text file. | ||
/// </summary> | ||
public class OutputTemplateRenderingBenchmark | ||
{ | ||
const string DefaultFileOutputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"; | ||
static readonly LogEvent HelloWorldEvent = Some.InformationEvent("Hello, {Name}", "World"); | ||
static readonly MessageTemplateTextFormatter Formatter = new MessageTemplateTextFormatter(DefaultFileOutputTemplate, CultureInfo.InvariantCulture); | ||
|
||
readonly StringWriter _output = new StringWriter(); | ||
|
||
[Setup] | ||
public void Setup() | ||
{ | ||
_output.GetStringBuilder().Length = 0; | ||
_output.GetStringBuilder().Capacity = 1024; // Only a few dozen chars actually needed here. | ||
} | ||
|
||
[Benchmark] | ||
public void FormatToOutput() | ||
{ | ||
Formatter.Format(HelloWorldEvent, _output); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters