Что будет быстрее?
public String Roll()
{
Random rnd = new Random();
int roll = rnd.Next(1, 100000);
if (Regex.IsMatch(roll.ToString(), @"(.)\1{1,}$"))
{
return "doubles";
}
return "none";
}
или
public String Roll()
{
Random rnd = new Random();
int roll = rnd.Next(1, 100000);
if (roll.ToString().EndsWith("11") || roll.ToString().EndsWith("22") || roll.ToString().EndsWith("33") || roll.ToString().EndsWith("44") || roll.ToString().EndsWith("55") || roll.ToString().EndsWith("66") || roll.ToString().EndsWith("77") || roll.ToString().EndsWith("88") || roll.ToString().EndsWith("99") || roll.ToString().EndsWith("00"))
{
return "doubles";
}
return "none";
}
В настоящее время я использую действительно длинный список операторов if, полный с регулярными выражениями, чтобы проверить, заканчивается ли int с удвоениями, тройками, квадратиками, квинтами и т.д.... поэтому я хотел бы знать, какой из них быстрее, прежде чем я изменюсь все это.