62,254
社区成员
发帖
与我相关
我的任务
分享StringBuilder sb = new StringBuilder(1024);
string str = "8912341253789";
for (int i = 0; i < 10000; i++)
{
sb.Append(str);
}
str = sb.ToString();
Stopwatch sw = new Stopwatch();
sw.Start();
Regex reg = new Regex(@"((\d)\d*)\2");
while (str != (str = reg.Replace(str, "$1"))) ;
sw.Stop();
richTextBox2.Text += "执行结果:" + str + "\n";
richTextBox2.Text += "执行时间:" + sw.ElapsedMilliseconds + " ms\n";
/*-------输出---------
执行结果:89123457
执行时间:90888 ms
*/StringBuilder sb = new StringBuilder(1024);
string str = "8912341253789";
for (int i = 0; i < 10000; i++)
{
sb.Append(str);
}
str = sb.ToString();
Stopwatch sw = new Stopwatch();
sw.Start();
Regex reg = new Regex(@"((\d)\d*?)\2");
while (str != (str = reg.Replace(str, "$1"))) ;
sw.Stop();
richTextBox2.Text += "执行结果:" + str + "\n";
richTextBox2.Text += "执行时间:" + sw.ElapsedMilliseconds + " ms\n";
/*--------输出----------
执行结果:89123457
执行时间:397 ms
*/