StringBuilder - rianjs/DotNetPerfTesting GitHub Wiki

.NET Core 2.2 on Intel 64


BenchmarkDotNet=v0.10.14, OS=macOS 10.15.3 (19D76) [Darwin 19.3.0]
Intel Core i7-8850H CPU 2.60GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=2.2.100
  [Host] : .NET Core 2.2.0 (CoreCLR 4.6.27110.04, CoreFX 4.6.27110.04), 64bit RyuJIT


Method Mean Error StdDev Median
StringConstructor 117.12 ns 2.284 ns 2.889 ns 118.00 ns
BuilderWithAppend 142.65 ns 3.012 ns 5.658 ns 141.37 ns
PerfectBuffer 53.28 ns 1.762 ns 5.083 ns 52.49 ns
NaiveBuffer 63.91 ns 1.974 ns 5.757 ns 61.87 ns
BigChunkWithTruncation 1,426.63 ns 30.852 ns 54.034 ns 1,412.05 ns
SmallChunkWithTruncation 180.55 ns 3.777 ns 3.709 ns 180.68 ns
BigChunkWithConditionalAppend 1,422.85 ns 18.616 ns 16.502 ns 1,417.22 ns
SmallChunkWithConditionalAppend 179.62 ns 4.050 ns 11.554 ns 174.70 ns

.NET 8 on M3 Mac


BenchmarkDotNet v0.13.12, macOS Sonoma 14.4 (23E214) [Darwin 23.4.0]
Apple M3, 1 CPU, 8 logical and 8 physical cores
.NET SDK 8.0.100
  [Host]   : .NET 8.0.0 (8.0.23.53103), Arm64 RyuJIT AdvSIMD
  ShortRun : .NET 8.0.0 (8.0.23.53103), Arm64 RyuJIT AdvSIMD

Job=ShortRun  IterationCount=3  LaunchCount=1  
WarmupCount=3  

Method Mean Error StdDev Gen0 Gen1 Allocated
StringConstructor 51.81 ns 1.355 ns 0.074 ns 0.1042 0.0001 872 B
BuilderWithAppend 60.67 ns 1.051 ns 0.058 ns 0.0802 - 672 B
PerfectBuffer 19.25 ns 0.187 ns 0.010 ns 0.0478 - 400 B
NaiveBuffer 24.85 ns 0.512 ns 0.028 ns 0.0813 - 680 B
BigChunkWithTruncation 226.90 ns 4.674 ns 0.256 ns 0.1566 0.0002 1312 B
SmallChunkWithTruncation 34.06 ns 1.543 ns 0.085 ns 0.0258 - 216 B
BigChunkWithConditionalAppend 242.51 ns 7.410 ns 0.406 ns 0.1564 - 1312 B
SmallChunkWithConditionalAppend 39.38 ns 49.968 ns 2.739 ns 0.0258 - 216 B
InterpolateAppend 998.99 ns 11,113.002 ns 609.141 ns 0.0935 - 792 B
NaiveAppend 465.65 ns 135.848 ns 7.446 ns 0.1326 - 1112 B
GuidInterpolation 25.12 ns 3.886 ns 0.213 ns 0.0210 - 176 B
GuidStringBuilder 91.86 ns 21.954 ns 1.203 ns 0.1204 - 1008 B