Skip to content

String recomposition

Rian Stockbower edited this page May 16, 2025 · 1 revision

String recomposition means rebuilding a string to get rid of duplicate spaces. Common when normalizing and extracting data from strings during data enrichment steps. For example, you have a regex that removes a phone number from a string, and another to extract a zip code or zip+4 which leaves you with a string like TST*SOME RESTAURANT HOLLYWOOD CA.

https://github.com/rianjs/DotNetPerfTesting/blob/master/PerfTesting/PerfTesting/Strings/RecomposeTests.cs

M3 MacBook Pro


BenchmarkDotNet v0.13.12, macOS 15.4.1 (24E263) [Darwin 24.4.0]
Apple M3, 1 CPU, 8 logical and 8 physical cores
.NET SDK 9.0.102
  [Host]   : .NET 8.0.12 (8.0.1224.60305), Arm64 RyuJIT AdvSIMD
  ShortRun : .NET 8.0.12 (8.0.1224.60305), Arm64 RyuJIT AdvSIMD

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

Method Mean Error StdDev Gen0 Gen1 Gen2 Allocated
ShortStringSplit 243.74 ns 88.890 ns 4.872 ns 0.1252 - - 1048 B
LongStringSplit 154,674.91 ns 5,055.441 ns 277.106 ns 57.1289 28.5645 28.5645 451869 B
ShortStringSpan 80.82 ns 25.858 ns 1.417 ns 0.0267 - - 224 B
LongStringSpan 61,990.92 ns 14,399.167 ns 789.267 ns 299.5605 299.5605 49.9268 184026 B
ShortStringBuilder 102.41 ns 1.636 ns 0.090 ns 0.0592 - - 496 B
LongStringBuilder 64,922.09 ns 17,505.003 ns 959.508 ns 299.5605 299.5605 49.9268 184074 B
Clone this wiki locally