I would like to know whats faster. Help me out.
I have a variable declared in a Method like so:
public static Regex FindNumber()
{ return new Regex(@"\d+", RegexOptions.IgnoreCase | RegexOptions.Compiled); }
As you can see it returns a Regular Expression.
I also have another Method that looks like so:
private static string TestOne(string RawData)
{
Regex rgxFindNumber = FindNumber();
Regex rgxFindDays = FindDays();
for (int i = 0; i < mc.Count; i++)
{
int days = Convert.ToInt32(rgxFindNumber.Match(rgxFindDays.Match(mc[i].Value).Value).Value);
}
return RawData;
}
Now is the TestOne Method going to be faster or is TestTwo?
private static string TestTwo(string RawData)
{
for (int i = 0; i < mc.Count; i++)
{
int days = Convert.ToInt32(FindNumber().Match( FindDays().Match(mc[i].Value).Value).Value);
}
return RawData;
}
Now im curious because TestOne Can get called a aweful lot in my code so I would like to know what would be better to implement.
Thanks guys.
Edit:The code I am using has an extremely large class. Its a text parser for a text based strategy game. I am trying to refactor it a bit and thats what I am wondering here. If I do create a private variable for the Regex, wouldn't it be run every time the class is accessed? Thats my question to you.