- 论坛徽章:
- 0
|
- #include <stdlib.h>
- #define ABS(a) ((a)>=0?(a):(-a))
- static volatile int array[256];
- static volatile int y1, y2;
- void ff1()
- {
- int i, j;
- for(i=0; i<1000; i++)
- for(j=0; j<256; j++)
- y1 += abs(array[j]);
- }
- void ff2()
- {
- int i, j;
- for(i=0; i<1000; i++)
- for(j=0; j<256; j++)
- y2 += ABS(array[j]);
- }
- int main()
- {
- int i;
- srand(time(NULL));
- for(i=0; i<256; i++)
- array[i] = rand();
-
- ff1();
- ff2();
-
- printf("y1=%d, y2=%d\n", y1, y2);
-
- return 0;
- }
复制代码
编译: gcc -pg -g -O3 aa.c
运行: a.exe
分析: gprof -b aa.exe
输出为:
- Flat profile:
- Each sample counts as 0.01 seconds.
- % cumulative self self total
- time seconds seconds calls Ts/call Ts/call name
- 100.00 0.01 0.01 main
- Call graph
- granularity: each sample hit covers 4 byte(s) for 100.00% of 0.01 seconds
- index % time self children called name
- <spontaneous>
- [1] 100.0 0.01 0.00 main [1]
- -----------------------------------------------
- Index by function name
- [1] main
复制代码
看不到函数ff1, ff2的信息。如果用-O2编译之后运行再用gprof分析是可以看到ff1, ff2的信息的。
请问对-O3有没有解决的办法呢? |
|