#include <chrono>
#define debug qDebug()<<
using namespace std::chrono;
int main(int argc, char *argv[])
{
std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();//获取一个时间点
auto t2 = std::chrono::system_clock::now();
auto t3 = std::chrono::high_resolution_clock::now();
int i = 0;
while (i < 100)
{
debug "hello world";
++i;
}
auto t4 = std::chrono::steady_clock::now();
auto t5 = std::chrono::system_clock::now();
auto t6 = std::chrono::high_resolution_clock::now();
std::chrono::steady_clock::duration d1 = t4- t1; //获取一段时间
std::chrono::system_clock::duration d2 = t5- t2;
std::chrono::high_resolution_clock::duration d3 = t6- t3;
debug "持续时间:"<< std::chrono::duration_cast<std::chrono::milliseconds>(d1).count() <<"毫秒";
debug "持续时间:"<< std::chrono::duration_cast<std::chrono::milliseconds>(d2).count() <<"毫秒";
debug "持续时间:"<< std::chrono::duration_cast<std::chrono::milliseconds>(d3).count() <<"毫秒";
debug "持续时间:"<< std::chrono::duration_cast<std::chrono::microseconds>(d1).count() <<"微秒";
debug "持续时间:"<< std::chrono::duration_cast<std::chrono::nanoseconds>(d1).count() <<"纳秒";
}
标准库时间
最新推荐文章于 2024-11-02 20:20:37 发布