String Benchmarks in C# - Refactoring for Speed/Maintainability

后端 未结 10 1412
无人及你
无人及你 2021-02-09 21:29

I\'ve been tinkering with small functions on my own time, trying to find ways to refactor them (I recently read Martin Fowler\'s book Refactoring: Improving the Design of Ex

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-09 22:06

    Try refactoring so that the regular expression that you're using to split the string in the second method is stored in a static method, and has been built using the RegexOptions.Compiled option. More info about this here: http://msdn.microsoft.com/en-us/library/8zbs0h2f.aspx.

    I didn't test the theory, but I'd imagine that having to recreate the regex every time would be time consuming.

提交回复
热议问题