C++ error LNK2001:无法解析的外部符号_imp_timeGetTime的解决办法
在文件头部添加
#pragma comment(lib, "winmm.lib")
#include <windows.h>
https://blog.youkuaiyun.com/qq_34504481/article/details/80924302
void test1()
{
time_t start,stop;
start = time(NULL);
foo();//dosomething
stop = time(NULL);
printf("Use Time:%ld\n",(stop-start));
}
void test3()
{
DWORD t1,t2;
t1 = timeGetTime();
foo();//dosomething
t2 = timeGetTime();
printf("Use Time:%f\n",(t2-t1)*1.0/1000);
}
https://www.cnblogs.com/dwdxdy/p/3214905.html
Linux C语言之计算程序段运行时间
struct timeval start;
struct timeval end;
float timer;
gettimeofday(&start,NULL);
func();
gettimeofday(&end,NULL);
timer = end.tv_sec - start.tv_sec + (float)(end.tv_usec - start.tv_usec)/1000000;
printf("timer = %fs\n",timer);
https://blog.youkuaiyun.com/donghanhang/article/details/50826112
auto t_start2 = std::chrono::high_resolution_clock::now();
程序
auto t_end2 = std::chrono::high_resolution_clock::now();
float ms2 = std::chrono::duration<float, std::milli>(t_end2 - t_start2).count();
VE_LOGI("FrcDataPrepare time : %f \n", ms2);
===========================================================================================
方法一(用这个方法):
#include <opencv2/opencv.hpp>
using namespace cv;
double t = (double)getTickCount();
fun();
t = ((double)getTickCount() - t) / getTickFrequency();
VE_LOGI("VeFrcProcess init_time=%f s.\n", t);
方法二:
#include <sys/time.h>
const int CLOCKS_PER_SEC_FIX = 1;
const int MILLISEC_PER_SEC = 1000;
const int MICROSEC_PER_SEC = 1000000;
struct timeval g_initStart, g_initEnd, g_processEnd;
gettimeofday(&g_initStart, nullptr);
fun();
gettimeofday(&g_initEnd, nullptr);
float initTime = (g_initEnd.tv_sec - g_initStart.tv_sec) * MICROSEC_PER_SEC + (g_initEnd.tv_usec - g_initStart.tv_usec);
printf("init use time = %f ms.\n", initTime * MILLISEC_PER_SEC / (CLOCKS_PER_SEC * CLOCKS_PER_SEC_FIX));