C#测试代码段运行速度
时间:2010-10-29 来源:迷梦江南
Stopwatch sw = new Stopwatch();
sw.Start();
int sum = 0;for (int i = 0; i < 100000; i++)
{
sum += i;
}
sw.Stop();
Label1.Text = "for循环:<br/>" + sw.Elapsed.ToString() + "<br/>";
sw.Reset();
sw.Start();
sum = 0;
int m = 100000;
while (m != 0)
{
sum += m;
m--;
}
sw.Stop();
Label1.Text += "while循环:<br/>" + sw.Elapsed.ToString() + "<br/>";
相关阅读 更多 +