DotNetStringBuilder is faster
alex-jitbit opened this issue · 2 comments
Seems like you removed the DotNetStringBuilder bench, but after adding it back this is what I get:
BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3593/23H2/2023Update/SunValley3)
AMD Ryzen 7 7800X3D, 1 CPU, 16 logical and 8 physical cores
.NET SDK 8.0.300
[Host] : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
ShortRun : .NET 8.0.5 (8.0.524.21615), X64 RyuJIT AVX-512F+CD+BW+DQ+VL+VBMI
Job=ShortRun IterationCount=3 LaunchCount=1
WarmupCount=3
| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|-------------------- |----------:|---------:|---------:|-------:|-------:|----------:|
| ValueStringBuilder | 176.37 ns | 62.05 ns | 3.401 ns | 0.0250 | - | 1.23 KB |
| DotNetStringBuilder | 97.29 ns | 35.04 ns | 1.920 ns | 0.0315 | 0.0001 | 1.54 KB |
Hey, thanks for reporting that.
That was a mistake - sometimes I, locally, don't care about the .net version but want to run the benchmark as baseline.
And I checked in that change (unintentionally).
The .NET internal one is more and more utilizing advanced techniques (just like this ValueStringBuilder
) making this library more and more obsolete, which I welcome!
The picture on .NET 9 and ARM64 (mac m2) looks not so clear:
| Method | Mean | Error | StdDev | Ratio | Gen0 | Allocated | Alloc Ratio |
|-------------------- |---------:|--------:|--------:|------:|-------:|----------:|------------:|
| DotNetStringBuilder | 125.0 ns | 0.97 ns | 0.91 ns | 1.00 | 0.1779 | 1.45 KB | 1.00 |
| ValueStringBuilder | 149.0 ns | 0.98 ns | 0.91 ns | 1.19 | 0.1452 | 1.19 KB | 0.82 |
There are also other scenarios where this library still has the upper hand:
| Method | Mean | Error | StdDev | Gen0 | Allocated |
|------------------------------- |---------:|----------:|----------:|-------:|----------:|
| DotNetStringBuilderAppendValue | 5.209 us | 0.0446 us | 0.0417 us | 0.7629 | 6.26 KB |
| ValueStringBuilderAppendValue | 5.179 us | 0.0228 us | 0.0213 us | 0.3281 | 2.71 KB |
If time allows I might find some low hanging fruits to close the gap to the System.Text.StringBuilder
.
I readded the benchmark