|
Console Library 8.0.0
A header-only library that makes C++ simple
|
表示以纳秒为单位的时间量,支持单位转换、算术运算和自动选择合适的输出单位。 More...
#include <time.h>
Public Member Functions | |
| Time (long long ns=0) | |
| 构造一个 Time 对象。 | |
| intmax_t | count () const |
| 获取纳秒数。 | |
| operator intmax_t () const | |
| 允许隐式转换为 intmax_t(返回纳秒数)。 | |
| double | ns () const |
| 返回纳秒数。 | |
| double | us () const |
| 返回微秒数。 | |
| double | ms () const |
| 返回毫秒数。 | |
| double | s () const |
| 返回秒数。 | |
| double | min () const |
| 返回分钟数。 | |
| double | hr () const |
| 返回小时数。 | |
| std::string | str () const |
| 将 Time 对象转换为字符串表示。 | |
Private Attributes | |
| intmax_t | ns_ |
| 纳秒数 | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Time t) |
| 输出 Time 对象到流,自动选择合适单位。 | |
| template<class Rep, class Period> | |
| Time | operator+ (Time t, std::chrono::duration< Rep, Period > d) |
| template<class Rep, class Period> | |
| Time | operator- (Time t, std::chrono::duration< Rep, Period > d) |
比较运算 | |
| bool | operator== (Time t1, Time t2) |
| bool | operator!= (Time t1, Time t2) |
| bool | operator< (Time t1, Time t2) |
| bool | operator> (Time t1, Time t2) |
| bool | operator<= (Time t1, Time t2) |
| bool | operator>= (Time t1, Time t2) |
算术运算 | |
| Time | operator* (double d) const |
| Time | operator/ (double d) const |
| Time | operator+ (Time t1, Time t2) |
| Time | operator- (Time t1, Time t2) |
表示以纳秒为单位的时间量,支持单位转换、算术运算和自动选择合适的输出单位。
内部使用 intmax_t 存储纳秒数,提供 ns()、us()、ms()、s()、min()、hr() 等转换函数。 输出流会根据时间大小自动选择最合适的单位(hr/min/s/ms/μs/ns)。
|
inline |
构造一个 Time 对象。
| ns | 纳秒数,默认为 0。 |
|
inline |
获取纳秒数。
|
inline |
返回小时数。
|
inline |
返回分钟数。
|
inline |
返回毫秒数。
|
inline |
返回纳秒数。
|
inline |
允许隐式转换为 intmax_t(返回纳秒数)。
|
inline |
|
inline |
|
inline |
返回秒数。
|
inline |
将 Time 对象转换为字符串表示。
|
inline |
返回微秒数。
|
friend |
|
friend |
|
friend |
|
private |
纳秒数