-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f560b2f
commit d187065
Showing
24 changed files
with
1,384 additions
and
43 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/ZeroLog.Benchmarks/Logging/StreamAppenderBenchmarks.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,48 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using BenchmarkDotNet.Attributes; | ||
using ZeroLog.Appenders; | ||
using ZeroLog.Configuration; | ||
using ZeroLog.Formatting; | ||
|
||
namespace ZeroLog.Benchmarks.Logging; | ||
|
||
[ShortRunJob] | ||
public class StreamAppenderBenchmarks | ||
{ | ||
private readonly Appender _standardFormatterAppender = new(false); | ||
private readonly Appender _utf8FormatterAppender = new(true); | ||
private readonly LoggedMessage _loggedMessage = new(1024, ZeroLogConfiguration.CreateTestConfiguration()); | ||
private readonly LogMessage _message; | ||
|
||
public StreamAppenderBenchmarks() | ||
{ | ||
_message = LogMessage.CreateTestMessage(LogLevel.Info, 1024, 32); | ||
_message.Append("Hello, ").Append("World! ").Append(42).AppendEnum(DayOfWeek.Friday).Append(new DateTime(2023, 01, 01)).Append(1024); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public void StandardFormatter() | ||
{ | ||
_loggedMessage.SetMessage(_message); | ||
_standardFormatterAppender.WriteMessage(_loggedMessage); | ||
} | ||
|
||
[Benchmark] | ||
public void Utf8Formatter() | ||
{ | ||
_loggedMessage.SetMessage(_message); | ||
_utf8FormatterAppender.WriteMessage(_loggedMessage); | ||
} | ||
|
||
private class Appender : StreamAppender | ||
{ | ||
public Appender(bool utf8Formatter) | ||
{ | ||
AllowUtf8Formatter = utf8Formatter; | ||
Stream = Stream.Null; | ||
Encoding = Encoding.UTF8; | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.