C/C++ Python计时

OpenCV C++计时

getTickCount()返回操作系统启动到当前所经过的计时周期
getTickFrequency()返回每秒的计时周期(即Tick Per Second)

int64_t start = cv::getTickCount();
XXX程序代码
int64_t end = cv::getTickCount();
double runtime = double(end - start) / double(cv::getTickFrequency()); // 计时单位: μs

getTickCount()函数在core.hpp中定义,返回值类型为int64,占用8个字节。
代码中我们使用了int64_t数据类型,之前出现过这样的情况:计时结果为负,将int改为int64_t后解决了此问题

Python计时

import time
start_t = time.time()
# type your code here
print("Runtime: {} seconds".format(time.time() - start_t))

猜你喜欢

转载自www.cnblogs.com/Todd-Qi/p/10865319.html