- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,让我说一下,我昨天才开始使用这个库,所以我对它的理解还很基础。我正在 try catch 我正在创建的视觉处理程序的 FPS,并使用 chrono 库将其输出到屏幕。在我的例子中,我需要将启动 steady_clock 后耗时转换为 double(或其他一些我可以像 double 一样对待的数字类型定义)。我查看了引用文档并尝试使用 duration_cast 和 time_point_cast 函数,但这两个似乎都不是我想要的。
我的问题是;有什么方法可以简单地将时钟当前状态的数值(以秒为单位)转换为原始数据类型?
如有任何帮助,我们将不胜感激。
最佳答案
像这样:
#include <chrono>
#include <iostream>
#include <thread>
int main()
{
using namespace std::literals;
// measure time now
auto start = std::chrono::system_clock::now();
// wait some time
std::this_thread::sleep_for(1s);
// measure time again
auto end = std::chrono::system_clock::now();
// define a double-precision representation of seconds
using fsecs = std::chrono::duration<double, std::chrono::seconds::period>;
// convert from clock's duration type
auto as_fseconds = std::chrono::duration_cast<fsecs>(end - start);
// display as decimal seconds
std::cout << "duration was " << as_fseconds.count() << "s\n";
}
示例输出:
duration was 1.00006s
关于c++ - 如何从 steady_clock 返回耗时作为原始数据类型 (double),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39812165/
有没有什么优雅的方法可以将 boost chrono time_point 转换为标准库中的等价物? 最佳答案 恐怕你不能保证转换,除非你先验地接受 boost::chrono::steady_clo
std::chrono::steady_clock 的单调属性是否跨线程保留?例如,假设我有以下程序。 #include #include #include using namespace st
在尝试在 SFML 中制定可靠的游戏循环的过程中,我遇到了这个我似乎无法弄清楚的问题。我能够去除所有 SFML 代码,但仍然在 time.h 中看到 clock() 的问题。然后我走得更远,仍然看到使
当我想生成几个线程以在设定的时间内进行一些计算时,我遇到了一个问题。但是经过的总时间总是大于每个线程分配时间的总和,而我预计它会超过最大值。我在这里不明白什么? 一些示例代码: #include #
chrono::steady_clock 由4种成员类型组成:rep , period , duration , 和 timepoint . chrono::steady_clock::duratio
我的应用服务器代码中有一行代码使用 steady_clock 获取时间戳值,如下所示: uint64_t now = duration_cast(steady_clock::now().time_si
使用 boost::chrono::steady_clock 或 std::chrono::steady_clock 可以保证物理时间始终是单调的并且不受日期时间的影响系统的变化。这是我的问题,如果我
首先,让我说一下,我昨天才开始使用这个库,所以我对它的理解还很基础。我正在 try catch 我正在创建的视觉处理程序的 FPS,并使用 chrono 库将其输出到屏幕。在我的例子中,我需要将启动
我有一个标题时间为 std::chrono::steady_clock 的文件范围。 不同的服务器会将它们写入磁盘。 在使用文件的过程中,我会比较它们以找到最新的时间。 我对 https://en.c
基本上: auto p1 = std::steady_clock::now().time_since_epoch().count(); ... // do smth for unspecified p
考虑这段代码: #include #include using namespace std::chrono_literals; int main() { auto sx = std::ch
我有以下代码: #include struct SteadyTime : std::chrono::steady_clock::time_point { using time_point::
我正在尝试将 C++ 代码转换为 Python。什么是 python 等价物,我可以用来替代 std::chrono::steady_clock::now(); 它给出了 linux 上当前时间的准确
我需要保存一个boost::chrono::steady_clock::time_point类型的变量到文件中,然后从文件中检索它。时间格式并不重要,我希望将其保存为双倍。这可能吗? 最佳答案 您可以
这与 my previous question 有关我问 std::chrono::steady_clock::now 是否应该是 noexcept。现在我知道了,我应该想知道这个函数是如何报告错误的
我正在使用 steady_clock 来保存一些消息的时间戳。出于调试目的,拥有日历(或类似的东西)很有用。 对于其他时钟,有静态函数 to_time_t,但在 GCC (MinGW 4.8.0) 上
我能做到: double period_in_seconds = 3.4; auto as_duration = std::chrono::duration_cast(std::chrono::dur
我正在尝试获取自处理器启动以来的微秒时间, 我看过很多发since epoch的帖子,但是我需要since power-up的时间 此外,我正在尝试将时间设为 long int,而不是 time_po
如何从 boost::chrono::steady_clock::now() 获得 double 值?我不相信为此有一个 .count() 参数。 为什么我需要这个?我有一个无法解析 boost 返回
所以准确的计时对我来说很重要,我正在研究 C++ 11 中指定的 3 种时钟,即 system_clock、steady_clock 和 high_resolution_clock。我最初关心的是测试
我是一名优秀的程序员,十分优秀!