gpt4 book ai didi

c++ - MSVC 16.8.4 中 std::this_thread::sleep 的大量开销?

转载 作者:行者123 更新时间:2023-12-05 03:45:25 30 4
gpt4 key购买 nike

在我们的渲染循环中,我们总是有一个格式为 this_thread::sleep_until(Thisframe + milliseconds(1000/60)); 的 FPS 限制器,但是在编译最新版本之后FPS 从未超过 32。所以玩了延迟,发现任何 sleep >= 1 微秒都会增加 5-16 毫秒。还有其他人注意到类似的事情吗?

// std::this_thread::sleep_for(std::chrono::nanoseconds(N));
------------------------------------------------------------
N | Max (ns) | Avg (ns) | Min (ns)
------------------------------------------------------------
1 541 532 530
10 526 526 523
100 526 526 525
1'000 5'105'253 5'035'142 4'945'181
10'000 15'849'245 15'829'724 15'751'297
100'000 15'900'155 15'884'466 15'846'923
1'000'000 15'885'041 15'877'936 15'872'767
10'000'000 15'899'457 15'884'640 15'881'723
// std::this_thread::sleep_for(std::chrono::nanoseconds(N));
------------------------------------------------------------
N | Avg (ns)
------------------------------------------------------------
3'000 17'759'597
2'500 13'888'173
2'000 10'093'005
1'500 9'393'417
1'000 4'735'949
750 2'841'692
700 5'445'165
650 4'658'634
600 2'153
500 1'789

最佳答案

感谢@Raymond Chen 对上述问题的评论解决了:

You might be seeing this: New Thread.Sleep behaviour under Windows 10 October Update 20H2. The system used to let you get away with somebody else cranking the timer resolution via timeBeginPeriod() (usually the web browser), but now it requires you to do it yourself.

关于c++ - MSVC 16.8.4 中 std::this_thread::sleep 的大量开销?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65851208/

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