#include <stdio.h>
#include <time.h>
#define max(a,b) a>b?a:b
/*int max(int a,int b)
{
return a>b?a:b;
}*/
void main (){
int t ,g ,c,i;
float now=0;
now=clock();
printf("%lf\n",now);
t=5;
g=2;
for(i=0;i<100000000;i++)
c=max(t,g);
printf("%d\n",c);
// printf("%lf",(clock()-now)/CLOCKS_PER_SEC);
printf("%f",clock()-now);
}
突然想比较下,定义宏max,和max函数,性能有多大差距。
采用#define max 的方式,执行时间为 0.207s,
使用max函数的方式,执行时间为1.533s,
显然定义宏要更省时间,不过这是使用了一亿次循环,所以要是平均到一次上,差距也是可以忽略不计的。
但有一点好处也还是应该采用的啊。