OVER 800x IMPROVEMENT?! Benchmarking Regular Expressions in C#
April 12, 2024
• 514 views
regex tutorialregular expressionregexregex find and replaceregular expression matchingregex testregex introregex how tosearch regexc# regexc# regular expressionshow to use regular expression in c#regex matching c#regular expression in c#regex in .netregular expressions c#regex in c#pattern matchinghow to use regex in c#regex examplesregex expression c#what is regexdotnetC#benchmarkdotnetbenchmarkbenchmarkingC# benchmarks
If you check out these benchmarks, you'll see a scenario that you might be doing in your very own code and you could be getting an 800x performance boost. And if you think there's no way you have a Regex in C# that will speed up by 800x, then you might see another benchmark where you could get a 100x gain!
In this video, I walk through the various ways that you can construct a regular expression in C# and the different performance characteristics of each. While this isn't an exhaustive benchmarking collection over a wide variety of C# regexes, hopefully, this serves as some inspiration to benchmark your code!
PLEASE NOTE: There is a critical flaw in the benchmark code as pointed out by a viewer (and THANK YOU for doing so in a very constructive and helpful way). You can read about the correction here:
https://www.devleader.ca/2024/04/12/csharp-regular-expression-benchmarks-how-to-avoid-my-mistakes/
