#include "time.h"
#include "stdio.h"
main()
{
/*
time_t lt;
lt=time(NULL);
/ *printf("%f\n",lt);* /
printf(ctime(lt));
printf(asctime(localtime(lt)));
printf(asctime(gmtime(lt)));
*/
time_t start,end;
int i;
start=time(NULL);
for(i=0;i<30000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=time(NULL);
printf("\1: The start is %2.7f\n",start);
printf("\1: The end is %2.7f\n",end);
printf("\1: The different is %6.3f\n",difftime(end,start));
/*
clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=clock();
printf("\1: The different is %6.3f\n",(double)(end-start));
*/
#include "stdio.h"
main()
{
/*
time_t lt;
lt=time(NULL);
/ *printf("%f\n",lt);* /
printf(ctime(lt));
printf(asctime(localtime(lt)));
printf(asctime(gmtime(lt)));
*/
time_t start,end;
int i;
start=time(NULL);
for(i=0;i<30000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=time(NULL);
printf("\1: The start is %2.7f\n",start);
printf("\1: The end is %2.7f\n",end);
printf("\1: The different is %6.3f\n",difftime(end,start));
/*
clock_t start,end;
int i;
double var;
start=clock();
for(i=0;i<10000;i++)
{
printf("\1\1\1\1\1\1\1\1\1\1\n");
}
end=clock();
printf("\1: The different is %6.3f\n",(double)(end-start));
*/
}
在计算时间差方面,clock_t,和time_t效果基本一致,只是各自有自已的api函数,用起来的基本差不多。Linux下面还有一个要注意sleep和usleep的和在windows下面有差距。