Why Compiled RegEx performance is slower than Intrepreted RegEx?

前端 未结 4 532
萌比男神i
萌比男神i 2020-12-05 07:47

I run into this article:

Performance: Compiled vs. Interpreted Regular Expressions, I modified the sample code to compile 1000 Regex and then run each 500 times to t

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-05 07:52

    The problem with this benchmark is that compiled Regexes have the overhead of creating a whole new assembly and loading it into the AppDomain.

    The scenario where compiled Regex was designed for (I believe -- I didn't design them) is having tens of Regexes executed millions of times, not thousands of Regexes executed thousands of times. If you're not going to execute a Regex in the realm of a million times, you probably won't even make up for the time to JIT compile it.

提交回复
热议问题