.NET Core 2.1 - Regex in loop 200x slower than 2.0 (3x in simple benchmark)

后端 未结 1 841
渐次进展
渐次进展 2020-12-31 02:44

I have the following regex:

    var regex = new Regex(
        @\"^ActiveMQ[\\d\\.-]*$\",
        RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOpt         


        
相关标签:
1条回答
  • 2020-12-31 03:33

    RegexOptions.Compiled is not implemented in .NET Core 2.0, but is implemented in .NET Core 2.1.

    Compilation involves initial overhead, and for certain usage patterns this overhead outweighs the gains of compiled regex.

    My case is somewhat complex, and it seems like there might be a bug in .NET, because even with a proper benchmark (with warm-up), Compiled mode is slower. See details in Corefx issue: https://github.com/dotnet/corefx/issues/30131

    0 讨论(0)
提交回复
热议问题