#include <time.h> #include <stdio.h> #include<sys/time.h> #define NEW_TIME_VALE struct timeval startTime,endTime; float Timeuse; #define START_GETTIME \ gettimeofday(&startTime,NULL); #define END_GETTIME \ gettimeofday(&endTime,NULL); Timeuse = 1000000*(endTime.tv_sec - startTime.tv_sec) + (endTime.tv_usec - startTime.tv_usec); Timeuse /= 1000000; printf("Timeuse = %f\n",Timeuse); void main() { NEW_TIME_VALE START_GETTIME sleep(1); END_GETTIME }
原文:http://www.cnblogs.com/mylinux/p/5295959.html