std::chrono::tai_clock::now
来自 cppreference.com
static std::chrono::time_point<std::chrono::tai_clock> now(); |
(自 C++20) | |
返回表示当前时间点的 time point。该结果的计算方式与使用 std::chrono::tai_clock::from_utc(std::chrono::utc_clock::now()) 相同。实现可以使用更准确的 TAI 时间值。
[编辑] 参数
(无)
[编辑] 返回值
表示当前时间的 time point。
[编辑] 示例
运行此代码
#include <chrono> #include <cstddef> #include <iomanip> #include <iostream> #include <numeric> #include <vector> volatile int sink; void do_some_work(std::size_t size) { std::vector<int> v(size, 42); sink = std::accumulate(v.begin(), v.end(), 0); // make sure it is a side effect } int main() { std::cout << std::fixed << std::setprecision(9) << std::left; for (auto size{1ull}; size < 10'00'00'00'00ull; size *= 100) { const auto start = std::chrono::tai_clock::now(); do_some_work(size); const auto end = std::chrono::tai_clock::now(); const std::chrono::duration<double> diff = end - start; std::cout << "Time to fill and iterate a vector of " << std::setw(9) << size << " ints : " << diff << '\n'; } }
可能的输出
Time to fill and iterate a vector of 1 ints : 0.000006568s Time to fill and iterate a vector of 100 ints : 0.000002854s Time to fill and iterate a vector of 10000 ints : 0.000116290s Time to fill and iterate a vector of 1000000 ints : 0.011742752s Time to fill and iterate a vector of 100000000 ints : 0.505534949s