CS代码:
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/>";