耗时统计

简单统计

#include<Windows.h>

DWORD startTime = GetTickCount();//计时开始
...代码块
DWORD endTime = GetTickCount();//计时结束
cout << "耗时:" << endTime - startTime << "ms" << endl;

复制代码
#include<Windows.h>

LARGE_INTEGER freq, start, end;

int main() {
    QueryPerformanceFrequency(&freq);
    QueryPerformanceCounter(&start);
    //...代码块
    QueryPerformanceCounter(&end);
    double cost = (end.QuadPart - start.QuadPart);
    cost = (cost * 1000 / freq.QuadPart); //ms

    return 0;
}
复制代码

精确统计

#include<chrono>

auto start=std::chrono::high_resolution_clock::now();
...代码块
auto end = std::chrono::high_resolution_clock::now();
cout << "耗时:" << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count() << "ms" << endl;

 OpenCV方式:

double t = (double)getTickCount();
// 需要被测量的程序段
t = ((double)getTickCount() - t)/getTickFrequency();
cout << "执行时间(秒): " << t << endl;

 

posted @   夕西行  阅读(64)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界
历史上的今天:
2020-03-31 PyCharm配置opencv环境,解决无法提示问题
点击右上角即可分享
微信分享提示