Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Significant overhead for std::this_thread::sleep in MSVC 16.8.4?

In our render-loop we've always had a FPS limiter in the form of this_thread::sleep_until(Thisframe + milliseconds(1000 / 60)); but after compiling on the latest version the FPS never went above 32. So played around with the delay and found that any sleep >= 1 micro-second added 5-16ms. Anyone else noticed something similar?

// 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
like image 320
Convery Avatar asked Nov 19 '25 00:11

Convery


1 Answers

Solved thanks to @Raymond Chen's comment on the question above:

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.

like image 74
Convery Avatar answered Nov 21 '25 13:11

Convery



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!