LoginSignup
0
0

More than 1 year has passed since last update.

Sleep性能評価(C++)

Last updated at Posted at 2022-01-30

概要

Sleep関数は現スレッドに対して処理を一定時間停止させる機能である.Sleep関数に停止時間を設定して処理を止める.

Sleep関数には停止時間に誤差が発生していることもある.
そこで,C++のSleep関数のSleep時間を設定したとき,実際の停止時間の誤差がどのくらいあるのか評価してみた.

測定

C++で提供されている代表的なSleep関数に対して精度を評価した.
評価方法は,1ミリ秒の停止(Sleep)を2000回実行したときの平均時間を算出して精度の評価を行った.
実行時間測定はchrono::steady_clockを使用した.

使用プログラム

Windows

WindowsのVisual Studio 2020 communityを用いて2種類のSleep関数に対して性能評価を行った.

Sleep関数 結果 備考
std::this_thread::sleep_for 15.559ミリ秒
Sleep 15.573ミリ秒
std::this_thread::sleep_for 2.010ミリ秒 timeBeginPeriod(1)を使用
Sleep 2.015ミリ秒 timeBeginPeriod(1)を使用
  • 開発環境:
    • Visual Studio 2022 community
  • PCスペック:
    • OS:Windows10 Pro(64bit)
    • CPU:Intel(R)Core(TM) i9-109000X 3.70GHz(物理コア数:10, 論理コア数:20)
    • メインメモリ:128GB

参考資料

  1. cpprefjp - C++日本語リファレンス, https://cpprefjp.github.io
  2. 性能評価プログラム, https://github.com/Ocean00000/SleepEvaluation
0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0