测试一段程序的运行时间

来源:互联网 发布:邮箱地址搜索软件 编辑:程序博客网 时间:2024/05/22 12:04
#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;}


打印出来的是程序运行的 微秒

原创粉丝点击