|
原帖由 xing83 于 2007-7-2 21:24 发表 ![]()
发现了,编译器果然把中间那个开根号的计算给忽略了
while (i
在我的AM2 3000+ 1G内存上运行两者一样慢。
LZ,其实你的程序根本不拷机,只是循环多而已。CPU负荷量是很小的。你可以试一下改写下循环,做同样的运算试试。
using System;
namespace ConsoleApplication1
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Test
{
public static void Main(string[] args)
{
/*
Test test = new Test();
int b = test.xun();
Console.WriteLine(b);
Console.ReadLine();
*/
double x = 0;
long sta = Environment.TickCount;
for (int i=1;i<1000;i++){
for (long l=1;l<300000;l+=4)
{
x=Math.Sqrt(l*l);
x=Math.Sqrt((l+1)*(l+1));
x=Math.Sqrt((l+2)*(l+2));
x=Math.Sqrt((l+3)*(l+3));
}
}
Console.WriteLine(Environment.TickCount - sta);
Console.ReadLine();
}
public int xun()
{
int a = 0;
int b = 9;
for(long i = 0;i < 1000000000;i++)
{
a++;
}
return b;
}
}
}
[ 本帖最后由 FENG950 于 2007-7-2 23:52 编辑 ] |
|