gcc编译优化选项-O, -O2

要运行的程序代码:

int main(void)
{
	double counter;
	double result;
	double temp;

	for (counter = 0; counter < 2000.0 * 2000.0 * 2000.0 /20.0 + 2200; counter += (5-1)/4)
	{
		temp = counter / 1979;
		result = counter;
	}
	printf("Result is %lf\\n", result);
	return 0;
}


编译后运行的过程:

[test5@cent4 cplus]$ time ./optimize
Result is 400002199.000000\n
real	0m9.041s
user	0m8.988s
sys	0m0.025s
[test5@cent4 cplus]$ time ./optimize1
Result is 400002199.000000\n
real	0m1.589s
user	0m1.585s
sys	0m0.002s
[test5@cent4 cplus]$ time ./optimize2
Result is 400002199.000000\n
real	0m1.574s
user	0m1.566s
sys	0m0.007s

看来有加上优化选项-O或者-O2效果还是有明显的差别的。

你可能感兴趣的:(gcc编译优化选项-O, -O2)