はじめに
こちらはDXライブラリ関数の時間計測の記事です。
各関数の処理時間を一覧にして掲載しています。
DXライブラリはこちらからダウンロードできます。
何か不備がありましたら指摘していただければ幸いです。
追記: コメントを頂き、"UpdateKey"と"UpdateKey2"のコード、計測結果を変更しました (2017/12/11)
ルール (決まりごと)
メインルール
100万回ループさせて計測する。
計測は10回行う。
計測結果の平均値を求める。
サブルール
線画の始点座標は(100,100)、終点座標は(300,300)とする。
中心点を指定する際は座標を(200,200)とする。
必要となる変数はその都度コメントアウトを外す。
環境
PC:HP Spectre x360 Convertible 13-ac0XX
CPU:Intel Corei7-7500U @ 2.70GHz 2.90GHz
RAM:16.0GB
ROM:SSD 512GB
IDE:VisualStudio Community 2017
cl; C/C++ Compiler 19.11
結果
名前 |
分類 |
時間(ミリ秒) |
GetPixel |
dxlib.h |
544872 |
DrawCircle(TRUE) |
dxlib.h |
22793.8 |
DrawCircleAA(TRUE) |
dxlib.h |
17483.2 |
DrawBoxAA(TRUE) |
dxlib.h |
16864.4 |
clsDx |
dxlib.h |
12893.7 |
DrawCircle(FALSE) |
dxlib.h |
12686.8 |
DrawCircleAA(FALSE) |
dxlib.h |
10445.5 |
DrawBoxAA(FALSE) |
dxlib.h |
8636.3 |
DrawLineAA |
dxlib.h |
7455.2 |
DrawFormatString3 |
dxlib.h |
7057.2 |
DrawRotaGraph(TRUE) |
dxlib.h |
6850.2 |
DrawTurnGraph(TRUE) |
dxlib.h |
6683.1 |
DrawTurnGraph(FALSE) |
dxlib.h |
6665.2 |
LoadGraph |
dxlib.h |
6655.7 |
DrawGraph(TRUE) |
dxlib.h |
6643.9 |
DrawModiGraph(TRUE) |
dxlib.h |
6641.6 |
DrawExtendGraph(TRUE) |
dxlib.h |
6637.3 |
DrawGraph(FALSE) |
dxlib.h |
6607 |
DrawBox(TRUE) |
dxlib.h |
5927.9 |
SRand |
dxlib.h |
2342.4 |
printfDx |
dxlib.h |
2054 |
DrawFormatString1 |
dxlib.h |
1730.6 |
DrawString |
dxlib.h |
1378.5 |
WaitTimer |
dxlib.h |
1000 |
DrawFormatString2 |
dxlib.h |
856.9 |
UpdateKey |
UpdateKey |
683 |
UpdateKey2 |
UpdateKey |
554.1 |
DrawBox(FALSE) |
dxlib.h |
441.3 |
CheckHitKeyAll |
dxlib.h |
385.2 |
DrawLine |
dxlib.h |
175.2 |
GetHitKeyStateAll |
dxlib.h |
119.7 |
DrawPixel |
dxlib.h |
61.9 |
CheckHitKey |
dxlib.h |
23.3 |
xor128 |
xor128 |
22.1 |
tan |
math.h |
18 |
cos |
math.h |
14.9 |
sin |
math.h |
14.2 |
GetRand |
dxlib.h |
11.9 |
GetJoypadInputState |
dxlib.h |
7 |
sqrt |
math.h |
6 |
GetColor |
dxlib.h |
4.9 |
GetJoypadNum |
dxlib.h |
4 |
GetTouchInputNum |
dxlib.h |
2 |
1000ミリ秒=1秒
精度は1ミリ秒程度ある。
コード
main.cpp
# include "DxLib.h"
# include <stdio.h>
# include <chrono>
//#include <math.h>
//横画面サイズ
# define MAP_X 400
//縦画面サイズ
# define MAP_Y 400
/*メイン関数*/
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
//log出力停止・ウィンドウモード変更・初期化・裏画面設定
SetOutApplicationLogValidFlag(FALSE), ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen(DX_SCREEN_BACK);
//画面サイズの決定
SetGraphMode(MAP_X, MAP_Y, 32);
//タイトル文字
SetMainWindowText("指定");
printfDx("名前 20XX年XX月XX日\n");
//データ保存先
FILE *fp;
errno_t error;
error = fopen_s(&fp, "指定.txt", "w");
if (!error) {
//char Buf[256];
//int Key[256] = { 0 };
//int Handle;
//int Handle = LoadGraph("picture.png");
//int intNumber = 0;
//double doubleNumber = 0;
//unsigned long ulomgNumber = 0;
//int intAfter = 0;
//int uintAfter = 0;
//double doubleAfter = 0;
//平均値
int ave = 0;
//計測時間(ミリ秒)
int timeMS;
//unsigned int White = GetColor(255, 255, 255);
std::chrono::system_clock::time_point start, end;
for (int j = 0; j < 10; j++) {
//intNumber = GetRand(999);
//doubleNumber = (double)GetRand(999);
//計測開始時間
start = std::chrono::system_clock::now();
for (int i = 0; i < 1000000; i++) {
//処理を書く
}
//計測終了時間
end = std::chrono::system_clock::now();
timeMS = (int)std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
ave += timeMS;
fprintf(fp, "%d\n", timeMS);
printfDx("%d:%d\n", j + 1, timeMS);
}
fclose(fp);
printfDx("平均:%d\n", ave / 10);
WaitKey();
}
//DXライブラリの終了処理
DxLib_End();
return 0;
}
図形描画関数
DrawLine(100, 100, 300, 300, White);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawLine |
188 |
173 |
174 |
173 |
173 |
175 |
174 |
175 |
173 |
174 |
175.2 |
DrawLineAA(100.0f, 100.0f, 300.0f, 300.0f, White);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawLineAA |
7520 |
7443 |
7431 |
7443 |
7542 |
7399 |
7446 |
7479 |
7451 |
7398 |
7455.2 |
DrawBox(TRUE)
DrawBox(100, 100, 300, 300, White, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawBox(TRUE) |
5932 |
5878 |
5987 |
5911 |
5901 |
5988 |
5916 |
5884 |
5984 |
5898 |
5927.9 |
DrawBox(FALSE)
DrawBox(100, 100, 300, 300, White, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawBox(FALSE) |
463 |
437 |
452 |
438 |
437 |
437 |
437 |
438 |
438 |
436 |
441.3 |
DrawBoxAA(TRUE)
DrawBoxAA(100.0f, 100.0f, 300.0f, 300.0f, White, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawBoxAA(TRUE) |
16798 |
16732 |
16834 |
16805 |
16946 |
16829 |
17055 |
16823 |
17028 |
16794 |
16864.4 |
DrawBoxAA(FALSE)
DrawBoxAA(100.0f, 100.0f, 300.0f, 300.0f, White, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawBoxAA(FALSE) |
8843 |
8681 |
8344 |
8329 |
8624 |
8839 |
8755 |
8843 |
8544 |
8561 |
8636.3 |
DrawCircle(TRUE)
DrawCircle(200, 200, 100, White, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawCircle(TRUE) |
22691 |
22638 |
22649 |
22800 |
22718 |
22745 |
22863 |
22755 |
22827 |
23252 |
22793.8 |
DrawCircle(FALSE)
DrawCircle(200, 200, 100, White, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawCircle(FALSE) |
12788 |
12732 |
12687 |
12683 |
12665 |
12650 |
12681 |
12638 |
12656 |
12688 |
12686.8 |
DrawCircleAA(TRUE)
DrawCircleAA(200.0f, 200.0f, 100.0f, 32, White, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawCircleAA(TRUE) |
17335 |
17646 |
17352 |
17342 |
17327 |
17261 |
17802 |
17390 |
17948 |
17429 |
17483.2 |
DrawCircleAA(FALSE)
DrawCircleAA(200.0f, 200.0f, 100.0f, 32, White, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawCircleAA(FALSE) |
9983 |
10375 |
10598 |
10481 |
10633 |
10369 |
10504 |
10537 |
10513 |
10462 |
10445.5 |
DrawPixel(200, 200, White);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawPixel |
73 |
75 |
57 |
60 |
57 |
61 |
57 |
61 |
57 |
61 |
61.9 |
uintAfter = GetPixel(200, 200);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetPixel |
525144 |
512430 |
516162 |
518323 |
525807 |
568150 |
571016 |
572251 |
574383 |
565054 |
544872 |
その他画面操作系関数
White = GetColor(255, 255, 255);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetColor |
5 |
5 |
4 |
5 |
5 |
5 |
5 |
5 |
5 |
5 |
4.9 |
乱数取得関数
intAfter = GetRand(intNumber);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetRand |
9 |
9 |
9 |
9 |
9 |
9 |
9 |
41 |
9 |
6 |
11.9 |
intAfter = SRand(intNumber);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
SRand |
2443 |
2329 |
2330 |
2332 |
2334 |
2328 |
2335 |
2333 |
2333 |
2327 |
2342.4 |
文字描画関係関数
DrawString(100, 100, "HelloWorld", White);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawString |
1495 |
1363 |
1366 |
1367 |
1363 |
1362 |
1364 |
1370 |
1365 |
1370 |
1378.5 |
DrawFormatString1
DrawFormatString(100, 100, White, "HelloWorld");

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawFormatString1 |
1856 |
1716 |
1718 |
1721 |
1714 |
1716 |
1714 |
1718 |
1715 |
1718 |
1730.6 |
DrawFormatString2
DrawFormatString(100, 100, White, "%d", intNumber);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawFormatString2 |
1065 |
883 |
708 |
816 |
821 |
863 |
864 |
819 |
865 |
865 |
856.9 |
DrawFormatString3
DrawFormatString(100, 100, White, "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorld");

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawFormatString3 |
7181 |
7014 |
7035 |
7061 |
7039 |
7059 |
7029 |
7047 |
7049 |
7058 |
7057.2 |
簡易画面出力関数

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
printfDx |
2157 |
2042 |
2040 |
2040 |
2049 |
2045 |
2043 |
2041 |
2040 |
2043 |
2054 |

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
clsDx |
13009 |
12920 |
12876 |
12894 |
12877 |
12874 |
12875 |
12858 |
12886 |
12868 |
12893.7 |
ウエイト関係の関数

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
WaitTimer |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
1000 |
グラフィックデータ制御関数
Handle = LoadGraph("picture.png");

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
LoadGraph |
53258 |
1481 |
1479 |
1478 |
1479 |
1478 |
1478 |
1471 |
1478 |
1477 |
6655.7 |
DrawGraph(TRUE)
DrawGraph(100, 100, Handle, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawGraph(TRUE) |
6624 |
6616 |
6688 |
6613 |
6612 |
6701 |
6639 |
6587 |
6728 |
6631 |
6643.9 |
DrawGraph(FALSE)
DrawGraph(100, 100, Handle, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawGraph(FALSE) |
6564 |
6525 |
6610 |
6528 |
6526 |
6608 |
6613 |
6669 |
6737 |
6690 |
6607 |
DrawTurnGraph(TRUE)
DrawTurnGraph(100, 100, Handle, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawTurnGraph(TRUE) |
6695 |
6653 |
6744 |
6663 |
6660 |
6738 |
6632 |
6624 |
6759 |
6663 |
6683.1 |
DrawTurnGraph(FALSE)
DrawTurnGraph(100, 100, Handle, FALSE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawTurnGraph(FALSE) |
6600 |
6558 |
6643 |
6555 |
6555 |
6637 |
6629 |
6952 |
6789 |
6734 |
6665.2 |
DrawExtendGraph(TRUE)
DrawExtendGraph(100, 100, 300, 300, Handle, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawExtendGraph(TRUE) |
6623 |
6580 |
6665 |
6584 |
6631 |
6668 |
6585 |
6602 |
6786 |
6649 |
6637.3 |
DrawRotaGraph(TRUE)
DrawRotaGraph(200, 200, 1.0f, doubleNumber, Handle, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawRotaGraph(TRUE) |
6792 |
6754 |
6816 |
6813 |
6790 |
6854 |
6842 |
6918 |
6987 |
6936 |
6850.2 |
DrawModiGraph(TRUE)
DrawModiGraph(100, 100, 300, 100, 300, 300, 100, 300, Handle, TRUE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
DrawModiGraph(TRUE) |
6625 |
6596 |
6678 |
6603 |
6600 |
6685 |
6606 |
6605 |
6756 |
6662 |
6641.6 |
キーボード入力関連関数
intAfter = CheckHitKeyAll();

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
CheckHitKeyAll |
413 |
363 |
543 |
383 |
360 |
358 |
359 |
357 |
358 |
358 |
385.2 |
intAfter = CheckHitKey(KEY_INPUT_ESCAPE);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
CheckHitKey |
25 |
26 |
27 |
43 |
22 |
18 |
18 |
18 |
18 |
18 |
23.3 |

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetHitKeyStateAll |
188 |
107 |
111 |
108 |
107 |
107 |
107 |
107 |
125 |
130 |
119.7 |
ジョイパッド入力関連関数
intAfter = GetJoypadNum();

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetJoypadNum |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
intAfter = GetJoypadInputState(DX_INPUT_PAD1);

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetJoypadInputState |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
7 |
タッチパネル入力関連関数
intAfter = GetTouchInputNum();

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
GetTouchInputNum |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
DXライブラリ以外の関数
xor128
unsigned long xor128() {
static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 886751230;
unsigned long t = (x ^ (x << 11));
x = y; y = z; z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
xor128 |
25 |
25 |
25 |
40 |
19 |
18 |
17 |
17 |
17 |
18 |
22.1 |
UpdateKey
UpdateKey1
int Key[256] = { 0 };
int UpdateKey() {
char Buf[256];
GetHitKeyStateAll(Buf);
for (int i = 0; i < 256; i++) {
if (Buf[i]) {
if (Key[i] != std::numeric_limits<int>::max()) Key[i]++;
}
else {
Key[i] = 0;
}
}
return 0;
}

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
UpdateKey1 |
745 |
678 |
675 |
677 |
675 |
675 |
675 |
677 |
674 |
679 |
683 |
UpdateKey2
int UpdateKey2(int *Key) {
char Buf[256];
GetHitKeyStateAll(Buf);
for (int i = 0; i < 256; i++) {
if (Buf[i]) {
if (Key[i] != std::numeric_limits<int>::max()) Key[i]++;
}
else {
Key[i] = 0;
}
}
return 0;
}

|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
UpdateKey2 |
626 |
570 |
542 |
543 |
545 |
542 |
542 |
544 |
542 |
545 |
554.1 |
math.h関数
sin
doubleAfter = sin(doubleNumber);
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
sin |
15 |
15 |
15 |
13 |
34 |
16 |
12 |
7 |
8 |
7 |
14.2 |
cos
doubleAfter = cos(doubleNumber);
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
cos |
13 |
13 |
14 |
14 |
13 |
45 |
11 |
9 |
9 |
8 |
14.9 |
tan
doubleAfter = tan(doubleNumber);
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
tan |
20 |
25 |
20 |
39 |
20 |
13 |
10 |
13 |
10 |
10 |
18 |
sqrt
doubleAfter = sqrt(doubleNumber);
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
平均 |
sqrt |
6 |
6 |
6 |
6 |
6 |
6 |
6 |
6 |
6 |
6 |
6 |
ソースコードのライセンス
These codes are licensed under CC0.

ソースコードは自由に使用してください。
参考
DXライブラリ 関数リファレンスページ
新・C言語 ~ゲームプログラミングの館
C++でフリープラットフォームな時間計測