Skip to content

Commit

Permalink
Fix some dodgy string formatting benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
nblumhardt committed Jun 4, 2017
1 parent 9b99d7e commit 4b0e2be
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ public class MessageTemplateRenderingBenchmark
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.
}
readonly TextWriter _output = new NullTextWriter();

[Benchmark]
public void TemplateWithNoProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ public class OutputTemplateRenderingBenchmark
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.
}
readonly TextWriter _output = new NullTextWriter();

[Benchmark]
public void FormatToOutput()
Expand Down
160 changes: 160 additions & 0 deletions test/Serilog.PerformanceTests/Support/NullTextWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;
using System.IO;
using System.Text;

namespace Serilog.PerformanceTests.Support
{
class NullTextWriter : TextWriter
{
public override void Write(char value)
{
}

public override Encoding Encoding { get; } = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false);

public override void Write(bool value)
{
}

public override void Write(char[] buffer)
{
}

public override void Write(char[] buffer, int index, int count)
{
}

public override void Write(decimal value)
{
}

public override void Write(double value)
{
}

public override void Write(int value)
{
}

public override void Write(long value)
{
}

public override void Write(object value)
{
}

public override void Write(float value)
{
}

public override void Write(string value)
{
}

public override void Write(string format, object arg0)
{
}

public override void Write(string format, object arg0, object arg1)
{
}

public override void Write(string format, object arg0, object arg1, object arg2)
{
}

public override void Write(string format, params object[] arg)
{
}

public override void Write(uint value)
{
}

public override void Write(ulong value)
{
}

public override string ToString()
{
return String.Empty;
}

public override void Flush()
{
}

public override void WriteLine()
{
}

public override void WriteLine(bool value)
{
}

public override void WriteLine(char value)
{
}

public override void WriteLine(char[] buffer)
{
}

public override void WriteLine(char[] buffer, int index, int count)
{
}

public override void WriteLine(decimal value)
{
}

public override void WriteLine(double value)
{
}

public override void WriteLine(int value)
{
}

public override void WriteLine(long value)
{
}

public override void WriteLine(object value)
{
}

public override void WriteLine(float value)
{
}

public override void WriteLine(string value)
{
}

public override void WriteLine(string format, object arg0)
{
}

public override void WriteLine(string format, object arg0, object arg1)
{
}

public override void WriteLine(string format, object arg0, object arg1, object arg2)
{
}

public override void WriteLine(string format, params object[] arg)
{
}

public override void WriteLine(uint value)
{
}

public override void WriteLine(ulong value)
{
}
}
}

0 comments on commit 4b0e2be

Please sign in to comment.