一.QT程序在提升程序性能的调试中经常要计算一段程序的执行时间,下面介绍两种简单的实现方式,精确度都可以达到ms。
1.方式一
(1)代码:
#include <QDateTime>
qDebug() << "Current_date_and_time start: " << QDateTime::currentDateTime();
for(int f = 0; f< 10000; ++f) {
std::vector<int> vec(10000);
for (int i = 0; i < 10000; ++i) {
vec[i] = i;
}
}
qDebug() << "Current_date_and_time end: " << QDateTime::currentDateTime();
(2)测试结果
Current_date_and_time start: QDateTime(2024-01-13 10: