linkdotnet/StringBuilder

ZString benchmarks are wrong and misleading

Stabzs opened this issue · 4 comments

Stabzs commented

You never dispose the ZString instance which means that the pooled buffer is never returned. This will dramatically impact performance.

As an aside, is this library based off of the dotnet/runtime ValueStringBuiilder? It seems to be nearly the same implementation, just split up.

You never dispose the ZString instance which means that the pooled buffer is never returned. This will dramatically impact performance.

Fair point - I will correct that. Anyway I thought of leaving out that comparison in the first place.
Here are the results with the updated version:

|                         Method |      Mean |    Error |   StdDev | Ratio | RatioSD |   Gen0 | Allocated | Alloc Ratio |
|------------------------------- |----------:|---------:|---------:|------:|--------:|-------:|----------:|------------:|
|            DotNetStringBuilder | 164.03 ns | 2.256 ns | 2.000 ns |  1.00 |    0.00 | 0.2370 |    1488 B |        1.00 |
|             ValueStringBuilder | 114.84 ns | 2.138 ns | 2.000 ns |  0.70 |    0.02 | 0.0892 |     560 B |        0.38 |
| ValueStringBuilderPreAllocated |  91.68 ns | 0.815 ns | 0.680 ns |  0.56 |    0.01 | 0.0892 |     560 B |        0.38 |
|             ZStringBuilderUtf8 | 137.06 ns | 2.699 ns | 3.213 ns |  0.84 |    0.02 | 0.0892 |     560 B |        0.38 |
|            ZStringBuilderUtf16 |  69.58 ns | 1.377 ns | 1.586 ns |  0.43 |    0.01 | 0.0892 |     560 B |        0.38 |

As an aside, is this library based off of the dotnet/runtime ValueStringBuiilder? It seems to be nearly the same implementation, just split up.

No, it did start out as an experiment to play with Span and friends. I checked the ValueStringBuilder on dotnet/runtime, and it has way fewer functions than the one you can find in this repository. But yes the idea is the same obviously as this is a common pattern.

Stabzs commented

I appreciate the background and that looks much better! I was expecting your library to be in parity with ZString and it is great to see that they're roughly the same. All in all, your library is another great option in the space!

Thanks for the tip about ZString - interesting to see those differences. Much appreciated.

Is it fine if I close the ticket?

Stabzs commented

Yes please. Thanks!