0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C++開発であると便利な機能

Last updated at Posted at 2022-05-02

はじめに

C++であると便利な機能を書きたいと思います。
詳細については都度追加していこうと思います。

機能一覧(随時追加予定)

・バイナリデータをログに出力
・処理時間を計測

処理時間を計測する

アプリの開発をしていと単体試験の時点では問題ないのに、
結合試験や、システム試験などでデータ量が増えたりした場合に、
処理が重くなって、どうしよう。。って事がよくあります。

そういう場合に、どこで処理が遅いかを調べる為に使います。
タイマー開始⇒重い処理⇒タイマー停止⇒停止から開始の時間をログ出力という流れです。

重い処理をどうやって軽くるするんだ?という問題は色々考えないといけないです。。

■手順:
VisualStudio2019を起動しファイル>新規作成>プロジェクトを選択します。
コンソールアプ(C++)を選択し次へを選択します。
適当にプロジェクト名を決めて作成を選択します。
ソースコードを書いて実行します。

main.cpp
#include <iostream>
#include <windows.h>
#pragma comment(lib, "winmm.lib")
int main()
{
    // 10回実行
    for (int i = 0; i < 10; i++)
    {
        DWORD startTime = timeGetTime();

        // 重い処理
        for (int j = 0; j < 1000 * 1000 * 1000; j++)
        {
            int a = 0;
            a %= 2;
        }

        // 掛かった時間を表示
        printf("number:%d, time:%d\n", (i + 1), (timeGetTime() - startTime));
    }
}

■結果

number:1, time:1669
number:2, time:1625
number:3, time:1641
number:4, time:1612
number:5, time:1623
number:6, time:1610
number:7, time:1663
number:8, time:1640
number:9, time:1590
number:10, time:1647
0
0
0

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?