简体   繁体   English

我怎么知道我的 `std::chrono::high_resolution_clock` 对应于 `steady_clock` 或 `system_clock` 的别名,或其他?

[英]How can I know my `std::chrono::high_resolution_clock` correspond to the alias of `steady_clock` or `system_clock`, or other?

How can I know my std::chrono::high_resolution_clock correspond to the alias of steady_clock or system_clock , or other?我怎么知道我的std::chrono::high_resolution_clock steady_clock std::chrono::high_resolution_clock对应于steady_clocksystem_clock的别名,或其他?

Many websites and books are providing examples using the system_clock , that might be goes back due to the synchronization, to measure the time spent for a function.许多网站和书籍都提供了使用system_clock示例,这可能由于同步而返回,以测量函数花费的时间。 I don't think that is the good idea to measure the time.我认为这不是衡量时间的好主意。 Instead, I think we should use std::chrono::steady_clock .相反,我认为我们应该使用std::chrono::steady_clock

Sometimes std::chrono::high_resolution_clock is used.有时使用std::chrono::high_resolution_clock According to the URL https://en.cppreference.com/w/cpp/chrono/high_resolution_clock , it says "It may be an alias of std::chrono::system_clock or std::chrono::steady_clock , or a third, independent clock."根据 URL https://en.cppreference.com/w/cpp/chrono/high_resolution_clock ,它说“它可能是std::chrono::steady_clock std::chrono::system_clockstd::chrono::steady_clock ,或者第三个,独立时钟。”

So, I want to know how can I check which aliases my std::chrono::high_resolution_clock correspond to.所以,我想知道如何检查std::chrono::high_resolution_clock对应的别名。 Any ideas?有任何想法吗?

Directly from Sam Varshavchik's comment.直接来自 Sam Varshavchik 的评论。 You can use std::is_same from <type_traits> to check if two types are the same.您可以使用<type_traits> std::is_same来检查两种类型是否相同。

Here's an example for checking the three standard clocks in chrono :这是检查chrono三个标准时钟的示例:

#include <chrono>
#include <iostream>
#include <type_traits>

int main() {
    using namespace std::chrono;

    std::cout << std::boolalpha
        << std::is_same_v<system_clock, high_resolution_clock> << '\n'
        << std::is_same_v<system_clock, steady_clock> << '\n'
        << std::is_same_v<high_resolution_clock, steady_clock> << '\n'
    ;
}

Demo演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 时间差与std :: chrono :: system_clock / std :: chrono :: high_resolution_clock - time differences with std::chrono::system_clock / std::chrono::high_resolution_clock std::chrono::system_clock 与 std::chrono::high_resolution_clock 行为 - std::chrono::system_clock vs std::chrono::high_resolution_clock behavior 在C ++实现中std :: chrono :: system_clock vs std :: chrono :: steady_clock的精度是多少? - Precision of std::chrono::system_clock vs std::chrono::steady_clock across C++ implementations? 不匹配的类型 'std::chrono::_V2::steady_clock' 和 'std::chrono::_V2::system_clock' - mismatched types 'std::chrono::_V2::steady_clock' and 'std::chrono::_V2::system_clock' std::system_clock 和 std::steady_clock 之间的区别? - Difference between std::system_clock and std::steady_clock? std::chrono::high_resolution_clock 的分辨率与测量值不对应 - Resolution of std::chrono::high_resolution_clock doesn't correspond to measurements 在整个系统中使用 std::chrono::steady_clock 时间是否正确? - Is it correct to use std::chrono::steady_clock time across the system? stable_clock 与 system_clock 之间的区别? - Difference between steady_clock vs system_clock? 同时获取steady_clock和system_clock - Get steady_clock and system_clock at the same time std :: chrono :: steady_clock :: now如何报告错误? - How does std::chrono::steady_clock::now report errors?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM