unoplatform/Uno.Roslyn

[Perf] Considering Replace StringBuilder with ZString

workgroupengineering opened this issue · 1 comments

ZString

Benchmark

BenchmarkDotNet=v0.13.1, OS=Windows 10.0.19044.1466 (21H2)
Intel Core i7-7700K CPU 4.20GHz (Kaby Lake), 1 CPU, 8 logical and 4 physical cores
.NET SDK=6.0.200-preview.22055.15
  [Host]   : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  .NET 5.0 : .NET 5.0.13 (5.0.1321.56516), X64 RyuJIT
  .NET 6.0 : .NET 6.0.1 (6.0.121.56705), X64 RyuJIT

Method Job Runtime Mean Error StdDev Median Ratio RatioSD Gen 0 Allocated native memory Native memory leak Gen 1 Gen 2 Allocated
ZStringFormatInt .NET 5.0 .NET 5.0 8.041 ms 0.0570 ms 0.0445 ms 8.032 ms 0.89 0.02 281.2500 - - 281.2500 281.2500 1,397 KB
AppendFormatInt .NET 5.0 .NET 5.0 9.057 ms 0.1811 ms 0.2155 ms 9.018 ms 1.00 0.00 906.2500 - - 562.5000 218.7500 4,315 KB
AppendFormatString .NET 5.0 .NET 5.0 2.955 ms 0.0590 ms 0.1064 ms 2.938 ms 0.33 0.02 640.6250 - - 500.0000 375.0000 3,134 KB
ZStringFormatString .NET 5.0 .NET 5.0 5.429 ms 0.0886 ms 0.1121 ms 5.417 ms 0.60 0.02 312.5000 - - 312.5000 312.5000 2,292 KB
ZStringFormatInt .NET 6.0 .NET 6.0 8.245 ms 0.1606 ms 0.1850 ms 8.189 ms 0.91 0.02 187.5000 - - 187.5000 187.5000 977 KB
AppendFormatInt .NET 6.0 .NET 6.0 8.542 ms 0.1834 ms 0.5380 ms 8.391 ms 0.93 0.06 890.6250 - - 562.5000 242.1875 4,315 KB
AppendFormatString .NET 6.0 .NET 6.0 2.395 ms 0.0440 ms 0.0411 ms 2.392 ms 0.27 0.01 636.7188 - - 515.6250 367.1875 3,134 KB
ZStringFormatString .NET 6.0 .NET 6.0 4.290 ms 0.0836 ms 0.1172 ms 4.287 ms 0.47 0.02 320.3125 - - 320.3125 320.3125 2,385 KB

Unfortunately, in most cases, it undesirable for generators to take an external dependency... We'll have to live with StringBuilder until it gets improved in later .NET builds.