std::chrono::
high_resolution_clock::now
静态公众成员函数 <chrono>
static time_point now() noexcept;
|
获取当前时间
返回high_resolution_clock中的当前时间点。
☲ 参数
-
none
☉ 返回值
表示当前时间的time_point。
Time_point是成员类型,定义为Time_point <high_resolution_clock>的别名.
☣ 示例
// high_resolution_clock example
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>
int main ()
{
using namespace std::chrono;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
std::cout << "printing out 1000 stars...\n";
for (int i=0; i<1000; ++i) std::cout << "*";
std::cout << std::endl;
high_resolution_clock::time_point t2 = high_resolution_clock::now();
duration<double> time_span = duration_cast<duration<double>>(t2 - t1);
std::cout << "It took me " << time_span.count() << " seconds.";
std::cout << std::endl;
return 0;
}
|
可能输出:
printing out 1000 stars...
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
********************************************************************************
****************************************
It took me 0.091001 seconds.
🍄 另请参阅