https://www.cnblogs.com/zlshmily/p/10058427.html
https://www.cnblogs.com/-citywall123/p/12623266.html
https://jingyan.baidu.com/article/63acb44aac1df421fcc17eff.html
https://blog.csdn.net/bladelyer/article/details/7180932
https://www.runoob.com/cprogramming/c-function-ctime.html
chrono 的概况
头文件 #include <chrono>
命名空间std::chrono
这个库从 C++11 引入标准之后,每个版本都有所修改,不过核心内容变化不是太大,他定义了三种主要类型,分别是 duration
、clocks
和 time points
,以及围绕这些类型的一些工具函数和衍生的定义。
chrono 的核心内容
duration
这个模板类用来表示时间间隔,我们知道时间的基本单位是秒,这个类的对象所表示的时间间隔也是以秒为单位的,它的定义如下:
template<class Rep, class Period = std::ratio<1>>
class duration;
Rep 表示一种数值类型,用来描述周期 Period 的数值类型,比如可以是 int、float 等,而 Period 的类型是std::ratio
,同样是一个模板类,实际表示的是一个有理数,像100、0、1/1000(千分之一)等等。
在 std 这个命名空间下有很多已经定义好的有理数,可以举几个常见的头文件<ratio>
中的例子:
nano std::ratio<1, 1000000000> // 十亿分之一
micro std::ratio<1, 1000000> // 百万分之一
milli std::ratio<1, 1000> // 千分之一
centi std::ratio<1, 100> // 百分之一
deci std::ratio<1, 10> // 十分之一
deca std::ratio<10, 1> // 十
hecto std::ratio<100, 1> // 百
kilo std::ratio<1000, 1> // 千