LoginSignup
0
1

More than 5 years have passed since last update.

【Windows】実行時間の計測

Last updated at Posted at 2017-02-15

概要

プログラムのある個所からある個所の実行までの実行時間を計測する。

[方法1] timeGetTime()

ネットで調べる限り、精度は1ミリ秒程度らしい。

ヘッダファイル

windows.hをインクルード。

外部ライブラリ

winmm.libをリンク必要あり。

リンク方法

■ VisualStudio(VC++)の統合開発環境で指定する
■ 自前でMakeファイルをゴリゴリ書く
■ コードで書く

関数の戻り値

timeGetTime() は DWORD 型(32ビット整数)を返す。
単位はミリ秒。

サンプルコード

#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "winmm.lib")

int main()
{
    // 開始時間
    DWORD s_tm = timeGetTime();

    /*************************/
    // 計測したい処理
    /*************************/

    // 終了時間
    DWORD e_tm = timeGetTime();

    // 実行時間
    DWORD = end - start;

    return 0;
}
0
1
4

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
1