您的位置:首页 > 其它

测试一段程序的运行时间

2013-11-13 18:11 197 查看
#include "stdio.h"
#include "sys/time.h"

int totalTimeTest()
{
    struct timeval  start,end;
    float  total;
    long long int i = 0;
    gettimeofday(&start,NULL);
    
    do {
        i++;
    }while (i != 10000000);
    
    gettimeofday(&end, NULL);
    total = 1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec);
    printf("use time is %f usec\n",total);
    return 0;
}

int main()
{
    totalTimeTest();
    return 0;
}


打印出来的是程序运行的 微秒
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: