C/C++ 测试某个模块耗时的代码

 
 
//列举三种常见测试耗时时间的代码
//1、使用#include <time.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
using namespace cv;

clock_t startT,finishT;
double usedT;startT = clock();
/******************/
//被测时间模块/
//******************/
finishT = clock();
usedT= double(finishT - startT)/CLOCKS_PER_SEC;printf("\ntime used is :%f ms\n",1000*usedT);}

//2、使用opencv中函数
int64 tbegin = cvGetTickCount();
/******************/
//被测时间模块//
/******************/
int64 tend = cvGetTickCount() - tbegin;
double a = tend / ((double)cvGetTickFrequency() * 1000);

//3、#include <unistd.h>
#include <unistd.h>
long tv_sec;/*秒*/
long tv_usec;/*微妙*/
struct timeval start, end;
gettimeofday(&start, NULL);
/******************/
//被测时间模块/
//******************/
gettimeofday(&end, NULL);
printf("ICE_VehiBrandRegProcess : time used %ld us\n",1000000 * (end.tv_sec - start.tv_sec) + (end.tv_usec - start.tv_usec));


猜你喜欢

转载自blog.csdn.net/qq_42189368/article/details/80341667
今日推荐