Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7717475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:54:32+00:00 2026-06-01T02:54:32+00:00

I understand the advantage of using RegexOptions.Compiled – it improves upon the execution time

  • 0

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 interpreting it at run-time. Although using this is not recommended for application which are already slow at start-up time.

But if my application can bear any slight increase in start-up time –
what are the other scenarios in which I should NOT use RegexOptions.Compiled?

Just as a note I am calling this method several times –

private static string GetName(string objString)
{
    return Regex.Replace(objString, "[^a-zA-Z&-]+", "");
}

So, this method is called with different values for ‘objString’ (although values for objString may repeat as well).

Do you think it’s good/not good to use RegexOptions.Compiled here?
Any web link would be really helpful.
Thank you!


EDIT

I tested my web app with both

  • RegexOptions.Compiled, and
  • Instantiate Regex as class variable

But couldn’t find any big difference in time taken by my web application –
Only thing I noticed in both scenarios is that first time when the application loads it’s taking double of the time taken compared to that in successive page loads and that is irrespective of whether I use RegexOptions.Compiled or not.

Any comments for —
why my web application takes longer for the Regex to process for first time and time taken is reduced to almost half or less in subsequent loads – Is there any inbuilt caching or some other .net feature is helping here.
P.S. This thing is same if I use RegexOptions.Compiled or not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:54:34+00:00Added an answer on June 1, 2026 at 2:54 am

    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 (from the days of .NET Framework 1.1), but from what I understand, none of the major relevant facts have changed since it was written.


    • Original blog link: https://blog.codinghorror.com/to-compile-or-not-to-compile/
    • Wayback Machine link (in case original link expires): https://web.archive.org/web/20140411223755/https://blog.codinghorror.com/to-compile-or-not-to-compile/
    • Original blog article heavily quotes this MSDN blog article: https://web.archive.org/web/20140413160809/http://blogs.msdn.com/b/bclteam/archive/2004/11/12/256783.aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the advantage of using Base64 encode? I would like to understand it
I'm struggling to understand the advantage of using the orange circle view controller in
I try to understand the advantage of Properties Triggers over Data Triggers in WPF.
What is the advantage of using a ConcurrentBag(Of MyType) against just using a List(Of
What's is the advantage of using Asynchronous processing in SQL Server over .NET Asynchronous
Could anyone point out the advantage of using assemblies, in the 'context' of ASP.NET
I understand the advantages of PROPERTIES over FIELDS, but I feel as though using
Unfortunately we are using the Advantage Database Server Torture Edition Version 8.1. After I
Is there any performance advantage to be had when using template parameters with static
I recieve some information about using binding source but I really don't understand explicitly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.