#include <stdio.h>
int main()
{
int i,j;
clock_t start,end;
for(j=0;j<3;j++)
{
start=clock();
for(i=0;i<=1000000000;i++);
end=clock();
printf("i++:%lf\n",(double)(end-start)/CLOCKS_PER_SEC);
start=clock();
for(i=1000000000;i>=0;i--);
end=clock();
printf("i--:%lf\n",(double)(end-start)/CLOCKS_PER_SEC);
}
return 0;
}
VC6测试结果:
i++:1.984000
i--:3.109000
i++:1.922000
i--:3.031000
i++:1.907000
i--:3.047000
说明i++比较快,原因未知