C ++ high

编程入门 行业动态 更新时间:2024-10-23 08:34:11
C ++ high_resolution_clock很奇怪的输出(C++ high_resolution_clock weird output)

我目前正在尝试计算cpp中循环的增量时间。 目前我使用此代码

#include <chrono> int main() { typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::duration<float> fsec; auto lastTime = Clock::now(); auto currentTime = Clock::now(); fsec passedTime = currentTime - lastTime; while (true) { lastTime = currentTime; printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); currentTime = Clock::now(); passedTime = currentTime - lastTime; printf("%i\n", passedTime.count()); } return 0; }

这不是我在程序中使用的实际代码,但增量时间计算和输出与此示例中的完全相同。

它曾经很好地工作,并且当GLFW锁定到60个刻度/秒时输出大约约0.0167,并且在大约6k刻度/秒时输出更低的数字。

我的问题是我将所有东西从main函数转移到一个方法中,现在得到这个结果

似乎我错误地改变了一些东西,但我无法弄清楚我改变了什么。

I am currently trying to calculate the delta time of a loop in cpp. Currently i use this code

#include <chrono> int main() { typedef std::chrono::high_resolution_clock Clock; typedef std::chrono::duration<float> fsec; auto lastTime = Clock::now(); auto currentTime = Clock::now(); fsec passedTime = currentTime - lastTime; while (true) { lastTime = currentTime; printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); printf(""); currentTime = Clock::now(); passedTime = currentTime - lastTime; printf("%i\n", passedTime.count()); } return 0; }

This is not the actual code i use in the program but the delta time calculation and the output is the exact same as in this sample.

It used to work fine and output a number of about ~0.0167 when locked to 60 ticks/s by GLFW and a ways lower number that at about 6k ticks/s.

My Problem is that I shifted everything out of the main function into a method and now get this result

It seems like I changed something by mistake but I can't figure out what I've changed.

最满意答案

你的printf错了,数据是浮点数,但printf格式是int。

Your printf is wrong, the data is a float, but the printf format is an int.

更多推荐

本文发布于:2023-07-16 07:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1125460.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:high

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!