std::chrono::
<steady_clock>
类 <chrono>
稳定时钟
提供对当前时间点访问的时钟类。
Steady_clock是专门设计用来计算时间间隔的。
☲ 时钟属性
-
不变
-
它的成员now永远不会返回比前一个调用更低的值(即 总是返回当前时间点)。
-
稳定
-
时钟每前进一瞬,所花费的时间都是相同的(以物理时间来说),这是一个实时时钟,不可更改。
☞ 成员类型
以下是steady_clock的成员类型的别名:
成员类型 |
定义 |
注释 |
rep |
算术类型(或模拟该类型的类) |
用于存储单位时间的计数器。 |
period |
一种比率类型 |
以秒为单位表示单位时间的比率类型。 |
time_point |
time_point<steady_clock> |
时钟的时间点类型。 |
duration |
duration<rep,period> |
时钟的持续时间类型 |
☞ 成员常量
☞ 静态成员函数
☣ 示例
// steady_clock example
#include <iostream>
#include <ctime>
#include <ratio>
#include <chrono>
int main ()
{
using namespace std::chrono;
steady_clock::time_point t1 = 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 t2 = steady_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.112006 seconds.
🍄 另请参阅
system_clock |
系统时钟(类) |
high_resolution_clock |
高精度时钟(类) |