String Benchmarks in C# - Refactoring for Speed/Maintainability

后端 未结 10 1414
无人及你
无人及你 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 21:54

    You might want to try instantiating a Regex object as a class member and using the RegexOptions.Compiled option when you create it.

    Currently, you're using the static Split member of Regex, and that doesn't cache the regular expression. Using an instanced member object instead of the static method should improve your performance even more (over the long run).

提交回复
热议问题