計算pi的平方根
/*
* pisqrt.c - Calculate the square of PI 100,000,000
*/
#include <stdio.h>
#include <math.h>
int main(void)
{
double pi = M_PI; /* Defined in <math.h> */
double pisqrt;
long i;
for(i = 0; i < 10000000; ++i) {
pisqrt = sqrt(pi);
}
return 0;
}
pisqrt的執行時間
標志/優化 平均執行時間
<none> 5.43s
-O1 2.74s
-O2 2.83s
-O3 2.76s
-ffloat-store 5.41s
-ffast-math 5.46s
-funroll-loops 5.44s
-fschedule-insns 5.45s
-fschedule-insns2 5.44s
這個例子說明,除非對處理器的體系結構非常了解或者知道某種特殊的優化專門針對你的程序有影響,否則就應該使用優化選項-O.
/*
* pisqrt.c - Calculate the square of PI 100,000,000
*/
#include <stdio.h>
#include <math.h>
int main(void)
{
double pi = M_PI; /* Defined in <math.h> */
double pisqrt;
long i;
for(i = 0; i < 10000000; ++i) {
pisqrt = sqrt(pi);
}
return 0;
}
pisqrt的執行時間
標志/優化 平均執行時間
<none> 5.43s
-O1 2.74s
-O2 2.83s
-O3 2.76s
-ffloat-store 5.41s
-ffast-math 5.46s
-funroll-loops 5.44s
-fschedule-insns 5.45s
-fschedule-insns2 5.44s
這個例子說明,除非對處理器的體系結構非常了解或者知道某種特殊的優化專門針對你的程序有影響,否則就應該使用優化選項-O.