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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…