引用:#include
#include
/*
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);
strut timeval {
long tv_sec; /* 秒数 */
long tv_usec; /* 微秒数 */
};
*/
struct timeval start,end;
int timeuse;
void time()
{
gettimeofday( &end, NULL );
timeuse = 1000000 * ( end.tv_sec - start.tv_sec ) + end.tv_usec - start.tv_usec;
timeuse /= 1000000;
printf("time used: %ds\n", timeuse);
}
void foo()
{
int i=0;
for(;i<10000;i++);
}
int main()
{
gettimeofday( &start, NULL );
foo();
time();
return 0;
}
[ 本帖最后由 hackersea 于 2008-8-5 00:14 编辑 ]