Help us understand the problem. What is going on with this article?

C++でフリープラットフォームな時間計測

More than 3 years have passed since last update.

c++で処理時間等を計測する際,clock()やtimeGetTime(), GetTickCount()等を用いていたものの,
clock()は精度が10msec程度(処理系依存)なため使い勝手があまり良くなく,GetTickCountは精度は良いもののwinmm.lib(windows系)で用意されている関数のためxcode等で使えない.

std::chrono

一方std::choronoはプラットフォームに依存せず,使い勝手もよい(精度は1msec程度の模様).
使い方は

#include <iostream>
#include <chrono>

int main(){
 std::chrono::system_clock::time_point  start, end; // 型は auto で可
 start = std::chrono::system_clock::now(); // 計測開始時間
// 処理
 end = std::chrono::system_clock::now();  // 計測終了時間
 double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); //処理に要した時間をミリ秒に変換

}

となっている.
std::chrono::duration_cast<変換型>(duration)の変換型には,ナノ秒(nanoseconds),マイクロ秒(microseconds),ミリ秒(microseconds),秒(seconds) を指定できる.

xcoo
ゲノムおよび生体情報解析のトータルソリューション「Chrovis」の開発をしています。
https://xcoo.co.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした