c++ 程序执行时间

opencv的:


//created:2020.04.06 by Andison
 
#include<iostream>
#include<vector>
#include<algorithm>
#include <opencv2/opencv.hpp>
using namespace std;
//读取路径下的特定格式文件的路径,返回按文件名升序排列的文件路径vector
int getFilePaths(vector<string> &filepaths, cv::String filePath);
 
int main()
{
	vector<string> filePaths;
	cv::String folderPath = "C:\\Users\\sun\\Desktop\\paths\\*.txt";
	double t1 = cv::getTickCount();
	getFilePaths(filePaths, folderPath);
	double t2 = cv::getTickCount();
	cout << "Time elapsed: " << 1000 * (double)(t2 - t1) / cv::getTickFrequency() <<" ms."<< endl;
 
	getchar();
	return 0;
}

 

单位ms:

		clock_t start_time = clock();
		auto faces = FD.detect(simage);
		clock_t finish_time = clock();
		double total_time = (double)(finish_time - start_time) / CLOCKS_PER_SEC;
		std::cout << "time" << total_time * 1000 << "ms" << std::endl;

 

使用时应该添加如下文件包含#include<windows.h> 。

程序执行时间:单位是ms,

DWORD start_time = GetTickCount();

printf("decode ok %d %u\n", avCodecCtx->flags, GetTickCount() - start_time);
                start_time = GetTickCount();

 

C++ clock()计时函数
核心:clock_t     s_time;        (double)(e_time-s_time)/CLOCKS_PER_SEC

#include <iostream>
#include <time.h>
using namespace std;
 
int main(int argc, const char * argv[])
{
    clock_t s_time, e_time;
    s_time=clock();
    for(int i=0; i<100000000; i++)
    {
        i-=1;    i+=1;
    }
    e_time=clock();
    cout<<"Total time:"<<(double)(e_time-s_time)/CLOCKS_PER_SEC<<"S"; 
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值