• <tfoot id='T8dwR'></tfoot>
  • <i id='T8dwR'><tr id='T8dwR'><dt id='T8dwR'><q id='T8dwR'><span id='T8dwR'><b id='T8dwR'><form id='T8dwR'><ins id='T8dwR'></ins><ul id='T8dwR'></ul><sub id='T8dwR'></sub></form><legend id='T8dwR'></legend><bdo id='T8dwR'><pre id='T8dwR'><center id='T8dwR'></center></pre></bdo></b><th id='T8dwR'></th></span></q></dt></tr></i><div id='T8dwR'><tfoot id='T8dwR'></tfoot><dl id='T8dwR'><fieldset id='T8dwR'></fieldset></dl></div>
    <legend id='T8dwR'><style id='T8dwR'><dir id='T8dwR'><q id='T8dwR'></q></dir></style></legend>
      <bdo id='T8dwR'></bdo><ul id='T8dwR'></ul>
  • <small id='T8dwR'></small><noframes id='T8dwR'>

      1. std::system_clock 和 std::steady_clock 的区别?

        Difference between std::system_clock and std::steady_clock?(std::system_clock 和 std::steady_clock 的区别?)
      2. <small id='qAiJQ'></small><noframes id='qAiJQ'>

        <legend id='qAiJQ'><style id='qAiJQ'><dir id='qAiJQ'><q id='qAiJQ'></q></dir></style></legend>

          <i id='qAiJQ'><tr id='qAiJQ'><dt id='qAiJQ'><q id='qAiJQ'><span id='qAiJQ'><b id='qAiJQ'><form id='qAiJQ'><ins id='qAiJQ'></ins><ul id='qAiJQ'></ul><sub id='qAiJQ'></sub></form><legend id='qAiJQ'></legend><bdo id='qAiJQ'><pre id='qAiJQ'><center id='qAiJQ'></center></pre></bdo></b><th id='qAiJQ'></th></span></q></dt></tr></i><div id='qAiJQ'><tfoot id='qAiJQ'></tfoot><dl id='qAiJQ'><fieldset id='qAiJQ'></fieldset></dl></div>
              <bdo id='qAiJQ'></bdo><ul id='qAiJQ'></ul>

                <tbody id='qAiJQ'></tbody>
                1. <tfoot id='qAiJQ'></tfoot>
                  本文介绍了std::system_clock 和 std::steady_clock 的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  std::system_clockstd::steady_clock 有什么区别?(说明不同结果/行为的示例案例会很棒).

                  What is the difference between std::system_clock and std::steady_clock? (An example case that illustrate different results/behaviours would be great).

                  如果我的目标是精确测量函数的执行时间(如基准测试),std::system_clockstd::steady_clock 之间的最佳选择是什么和 std::high_resolution_clock?

                  If my goal is to precisely measure execution time of functions (like a benchmark), what would be the best choice between std::system_clock, std::steady_clock and std::high_resolution_clock?

                  推荐答案

                  来自 N3376:

                  20.11.7.1 [time.clock.system]/1:

                  20.11.7.1 [time.clock.system]/1:

                  system_clock 类的对象表示来自系统范围实时时钟的挂钟时间.

                  Objects of class system_clock represent wall clock time from the system-wide realtime clock.

                  20.11.7.2 [time.clock.steady]/1:

                  20.11.7.2 [time.clock.steady]/1:

                  steady_clock 类的对象表示 time_point 的值不会随着物理时间的增加而减少的时钟,并且 time_point 的值以一定的速度增加相对于实时的稳定速率.也就是说,时钟可能不会被调整.

                  Objects of class steady_clock represent clocks for which values of time_point never decrease as physical time advances and for which values of time_point advance at a steady rate relative to real time. That is, the clock may not be adjusted.

                  20.11.7.3 [time.clock.hires]/1:

                  20.11.7.3 [time.clock.hires]/1:

                  high_resolution_clock 类的对象表示具有最短滴答周期的时钟.high_resolution_clock 可能是 system_clocksteady_clock 的同义词.

                  Objects of class high_resolution_clock represent clocks with the shortest tick period. high_resolution_clock may be a synonym for system_clock or steady_clock.

                  例如,系统范围的时钟可能会受到夏令时等因素的影响,此时列出的未来某个时间点的实际时间实际上可能是过去的时间.(例如在美国,在下降时间后移一小时,因此同一小时会经历两次")但是,steady_clock 不允许受此类事情的影响.

                  For instance, the system wide clock might be affected by something like daylight savings time, at which point the actual time listed at some point in the future can actually be a time in the past. (E.g. in the US, in the fall time moves back one hour, so the same hour is experienced "twice") However, steady_clock is not allowed to be affected by such things.

                  在这种情况下考虑稳定"的另一种方式是在 20.11.3 [time.clock.req]/2 表中定义的要求:

                  Another way of thinking about "steady" in this case is in the requirements defined in the table of 20.11.3 [time.clock.req]/2:

                  在表 59 中,C1C2 表示时钟类型.t1t2C1::now() 返回的值,其中返回 t1 的调用发生在调用之前返回 t2 并且这两个调用都发生在 C1::time_point::max() 之前.[ 注意:这意味着 C1 没有在 t1t2 之间回绕.——结尾说明]

                  In Table 59 C1 and C2 denote clock types. t1 and t2 are values returned by C1::now() where the call returning t1 happens before the call returning t2 and both of these calls occur before C1::time_point::max(). [ Note: this means C1 did not wrap around between t1 and t2. —end note ]

                  表达式:C1::is_steady
                  返回:const bool
                  操作语义:true 如果 t1 <= t2 始终为真并且时钟滴答之间的时间是恒定的,否则 false.

                  Expression: C1::is_steady
                  Returns: const bool
                  Operational Semantics: true if t1 <= t2 is always true and the time between clock ticks is constant, otherwise false.

                  这就是标准对它们的区别的全部内容.

                  That's all the standard has on their differences.

                  如果您想进行基准测试,最好的选择可能是 std::high_resolution_clock,因为您的平台很可能使用高分辨率计时器(例如 QueryPerformanceCountercode> 在 Windows 上)用于此时钟.但是,如果您要进行基准测试,您真的应该考虑将特定于平台的计时器用于您的基准测试,因为不同的平台对此有不同的处理方式.例如,某些平台可能会提供一些方法来确定程序所需的实际时钟滴答数(独立于在同一 CPU 上运行的其他进程).更好的是,获得一个真正的分析器并使用它.

                  If you want to do benchmarking, your best bet is probably going to be std::high_resolution_clock, because it is likely that your platform uses a high resolution timer (e.g. QueryPerformanceCounter on Windows) for this clock. However, if you're benchmarking, you should really consider using platform specific timers for your benchmark, because different platforms handle this differently. For instance, some platforms might give you some means of determining the actual number of clock ticks the program required (independent of other processes running on the same CPU). Better yet, get your hands on a real profiler and use that.

                  这篇关于std::system_clock 和 std::steady_clock 的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Constructor initialization Vs assignment(构造函数初始化 Vs 赋值)
                  Is a `=default` move constructor equivalent to a member-wise move constructor?(`=default` 移动构造函数是否等同于成员移动构造函数?)
                  Has the new C++11 member initialization feature at declaration made initialization lists obsolete?(声明时新的 C++11 成员初始化功能是否使初始化列表过时了?)
                  Order of constructor call in virtual inheritance(虚继承中构造函数调用的顺序)
                  How to use sfinae for selecting constructors?(如何使用 sfinae 选择构造函数?)
                  Initializing a union with a non-trivial constructor(使用非平凡的构造函数初始化联合)
                  <legend id='sKPEz'><style id='sKPEz'><dir id='sKPEz'><q id='sKPEz'></q></dir></style></legend>

                  <small id='sKPEz'></small><noframes id='sKPEz'>

                      • <bdo id='sKPEz'></bdo><ul id='sKPEz'></ul>

                              <tbody id='sKPEz'></tbody>
                            <i id='sKPEz'><tr id='sKPEz'><dt id='sKPEz'><q id='sKPEz'><span id='sKPEz'><b id='sKPEz'><form id='sKPEz'><ins id='sKPEz'></ins><ul id='sKPEz'></ul><sub id='sKPEz'></sub></form><legend id='sKPEz'></legend><bdo id='sKPEz'><pre id='sKPEz'><center id='sKPEz'></center></pre></bdo></b><th id='sKPEz'></th></span></q></dt></tr></i><div id='sKPEz'><tfoot id='sKPEz'></tfoot><dl id='sKPEz'><fieldset id='sKPEz'></fieldset></dl></div>

                          1. <tfoot id='sKPEz'></tfoot>