#include <stdio.h> #include <sys/time.h> #include <time.h> int gettimeofday(struct timeval*tv,struct timezone *tz); int main(int argc, char* argv[]) { int timeuse; struct timeval starttime,endtime; gettimeofday(&starttime,0); sleep(2); gettimeofday(&endtime,0); timeuse=(endtime.tv_sec-starttime.tv_sec)*1000000+endtime.tv_usec-starttime.tv_usec; timeuse/=1000 ; printf("the programme run %d second/n the result of 1+2+3+....100 ",timeuse); printf("Hello World! "); return 0; }
获取某个程序运行经历的时间差值.