gpt4 book ai didi

C++计时,自上一秒以来的毫秒数

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:49:51 34 4
gpt4 key购买 nike

我正在开发一个 C++ 应用程序,它需要精确到毫秒级的详细计时信息。

我们打算使用标准 time() 收集精确到秒的时间在 <ctime> 中发挥作用.我们还想收集自 time() 给出的最后一秒以来经过的毫秒数。 .

有谁知道获取这些信息的便捷方法吗?

最佳答案

Boost.DateTime 具有毫秒和纳秒表示形式如果底层平台支持它们。当它使用特定于平台的代码时,它会将这些细节保留在您的代码之外。

如果这很重要,他们确实有另一种方法来进行独立于平台的亚秒级分辨率。 This page几段下来讨论了如何去做。

(来自页面)

例如,假设我们要使用表示十分之一秒的计数来构造。也就是说,每个刻度为 0.1 秒。

int number_of_tenths = 5;
//create a resolution independent count -- divide by 10 since there are
//10 tenths in a second.
int count = number_of_tenths*(time_duration::ticks_per_second()/10);
time_duration td(1,2,3,count); //01:02:03.5 //no matter the resolution settings

关于C++计时,自上一秒以来的毫秒数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/117346/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com