使用 -OLevel 选项,在编译时对程序进行优化。level为相应的优化等级。
例如: gcc -Wall -O0 test.c -o o0
gcc -Wall -O5 test.c -o o5
使用命令 time 来查询程序运行效果:
debianerik:~/Desktop# time ./o0
1 to 1000000 sum is : 5e+11
real 0m0.005s
user 0m0.008s
sys 0m0.000s
debianerik:~/Desktop# time ./o5
1 to 1000000 sum is : 5e+11
real 0m0.004s
user 0m0.004s
sys 0m0.000s