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