使用gettimeofday测试函数运行的时间

 

#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
}

 

posted @ 2016-03-19 18:49  oucaijun  阅读(1234)  评论(0编辑  收藏  举报
下载TeamViewer完整版 下载TeamViewer