String.Replace performance improvements in .NET 6

The below String.Replace benchmarks show some solid performance improvements between .NET 5 v .NET 6… 

I’ve included other runtimes too as it’s fun to see the progress from runtime to runtime. There’s some huge improvements from .NET Framework 4.8 -> .NET 6, although it looks like a slight regression with .NET Core 3.1 for some scenarios. 

Click on the image for a larger view in a new tab…


Note 1 – The times above are in milliseconds but the sample text in this case is 15.2 MB which is quite large so your mileage will vary. 

Note 2 – Microsoft note that if the value to be replaced is very frequent (like every or every other character in the input), this change can actually regress performance… everything is a trade off right?

Leave a Reply

Your email address will not be published.