Skip to content

Commit 639e0ae

Browse files
committed
Updated benchmarks based on advice from @mattwarren
1 parent bd32c02 commit 639e0ae

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

test/Serilog.Formatting.Compact.Tests/BenchmarkDotNet.Artifacts/results/FormattingBenchmarks-report-github.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ JitModules=?
1111
Type=FormattingBenchmarks Mode=Throughput Toolchain=Core
1212

1313
```
14-
Method | Median | StdDev | Scaled |
15-
--------------------------------- |----------- |---------- |------- |
16-
JsonFormatter1000 | 11.6479 ms | 0.3343 ms | 1.00 |
17-
CompactJsonFormatter1000 | 6.1992 ms | 0.0448 ms | 0.53 |
18-
RenderedJsonFormatter1000 | 14.9243 ms | 0.1439 ms | 1.28 |
19-
RenderedCompactJsonFormatter1000 | 7.0540 ms | 0.0535 ms | 0.61 |
14+
Method | Median | StdDev | Scaled |
15+
----------------------------- |----------- |---------- |------- |
16+
JsonFormatter | 12.4016 us | 0.8737 us | 1.00 |
17+
CompactJsonFormatter | 6.0621 us | 0.0359 us | 0.49 |
18+
RenderedJsonFormatter | 15.6869 us | 0.9942 us | 1.26 |
19+
RenderedCompactJsonFormatter | 6.8628 us | 0.4178 us | 0.55 |
20+
| 0.0535 ms | 0.61 |
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Type;Method;Mode;Platform;Jit;Framework;Toolchain;Runtime;LaunchCount;WarmupCount;TargetCount;Affinity;Median;StdDev;Scaled
2-
FormattingBenchmarks;JsonFormatter1000;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;11.6479 ms;0.3343 ms;1.00
3-
FormattingBenchmarks;CompactJsonFormatter1000;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;6.1992 ms;0.0448 ms;0.53
4-
FormattingBenchmarks;RenderedJsonFormatter1000;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;14.9243 ms;0.1439 ms;1.28
5-
FormattingBenchmarks;RenderedCompactJsonFormatter1000;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;7.0540 ms;0.0535 ms;0.61
2+
FormattingBenchmarks;JsonFormatter;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;12.4016 us;0.8737 us;1.00
3+
FormattingBenchmarks;CompactJsonFormatter;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;6.0621 us;0.0359 us;0.49
4+
FormattingBenchmarks;RenderedJsonFormatter;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;15.6869 us;0.9942 us;1.26
5+
FormattingBenchmarks;RenderedCompactJsonFormatter;Throughput;Host;Host;Host;Core;Host;Auto;Auto;Auto;Auto;6.8628 us;0.4178 us;0.55
6+
0.0535 ms;0.61

test/Serilog.Formatting.Compact.Tests/BenchmarkDotNet.Artifacts/results/FormattingBenchmarks-report.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
</code></pre>
1212

1313
<table>
14-
<tr><th> Method</th><th>Median</th><th>StdDev</th><th>Scaled</th>
15-
</tr><tr><td> JsonFormatter1000</td><td>11.6479 ms</td><td>0.3343 ms</td><td>1.00</td>
16-
</tr><tr><td> CompactJsonFormatter1000</td><td>6.1992 ms</td><td>0.0448 ms</td><td>0.53</td>
17-
</tr><tr><td> RenderedJsonFormatter1000</td><td>14.9243 ms</td><td>0.1439 ms</td><td>1.28</td>
18-
</tr><tr><td>RenderedCompactJsonFormatter1000</td><td>7.0540 ms</td><td>0.0535 ms</td><td>0.61</td>
14+
<tr><th> Method</th><th>Median</th><th>StdDev</th><th>Scaled</th>
15+
</tr><tr><td> JsonFormatter</td><td>12.4016 us</td><td>0.8737 us</td><td>1.00</td>
16+
</tr><tr><td> CompactJsonFormatter</td><td>6.0621 us</td><td>0.0359 us</td><td>0.49</td>
17+
</tr><tr><td> RenderedJsonFormatter</td><td>15.6869 us</td><td>0.9942 us</td><td>1.26</td>
18+
</tr><tr><td>RenderedCompactJsonFormatter</td><td>6.8628 us</td><td>0.4178 us</td><td>0.55</td>
19+
</tr></table>
20+
td>
1921
</tr></table>

test/Serilog.Formatting.Compact.Tests/FormattingBenchmarks.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,36 @@ public FormattingBenchmarks()
2727
_evt = collectorSink.LastCollected;
2828
}
2929

30-
void Run(ITextFormatter formatter, int iterations)
30+
StringWriter _buffer;
31+
32+
[Setup]
33+
public void InitBuffer()
3134
{
32-
for (var i = 0; i < iterations; ++i)
33-
{
34-
var sw = new StringWriter();
35-
formatter.Format(_evt, sw);
36-
}
35+
_buffer = new StringWriter();
3736
}
3837

3938
[Benchmark(Baseline = true)]
40-
public void JsonFormatter1000()
39+
public void JsonFormatter()
4140
{
42-
Run(_jsonFormatter, 1000);
41+
_jsonFormatter.Format(_evt, _buffer);
4342
}
4443

4544
[Benchmark]
46-
public void CompactJsonFormatter1000()
45+
public void CompactJsonFormatter()
4746
{
48-
Run(_compactFormatter, 1000);
47+
_compactFormatter.Format(_evt, _buffer);
4948
}
5049

5150
[Benchmark]
52-
public void RenderedJsonFormatter1000()
51+
public void RenderedJsonFormatter()
5352
{
54-
Run(_renderedJsonFormatter, 1000);
53+
_renderedJsonFormatter.Format(_evt, _buffer);
5554
}
5655

5756
[Benchmark]
58-
public void RenderedCompactJsonFormatter1000()
57+
public void RenderedCompactJsonFormatter()
5958
{
60-
Run(_renderedCompactFormatter, 1000);
59+
_renderedCompactFormatter.Format(_evt, _buffer);
6160
}
6261
}
6362
}

0 commit comments

Comments
 (0)