When not to use RegexOptions.Compiled

前端 未结 4 1110
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 06:10

I understand the advantage of using RegexOptions.Compiled - it improves upon the execution time of app by having the regular expression in compiled form instead of interpre

4条回答
  •  半阙折子戏
    2020-12-13 06:20

    For any specific performance question like this, the best way to find out which way is faster is to test both and see.

    In general, compiling a regex is unlikely to have much benefit unless you're using the regex a lot, or on very large strings. (Or both.) I think it's more of an optimization to try after you've determined that you have a performance problem and you think this might help, than one to try randomly.

    For some general discussion on the drawbacks of RegexOptions.Compiled, see this blog post by Jeff Atwood; it's very old, but from what I understand, none of the major relevant facts have changed since it was written.

提交回复
热议问题