Last active
December 14, 2015 15:19
-
-
Save plonk/5106933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <windows.h> | |
| /* LARGE_INTEGER を表示する */ | |
| #define disp_large_int(x) printf(#x " = %lld\n", x.QuadPart) | |
| /* QueryPerformanceFrequency と ...Counter を使って | |
| Sleep(1000) を実行する間にたった時間を表示する */ | |
| int main(int argc, char **argv) | |
| { | |
| LARGE_INTEGER freq; // 秒間カウント | |
| LARGE_INTEGER a, b; // 開始時刻、終了時刻 | |
| LARGE_INTEGER diff; // 差 | |
| // プロセッサの数を限定 | |
| SetThreadAffinityMask(GetCurrentThread(), 1); | |
| // 1秒あたりのカウント数を取得 | |
| QueryPerformanceFrequency(&freq); | |
| // 計測開始 | |
| QueryPerformanceCounter(&a); | |
| // 1秒寝る | |
| Sleep( 1000 ); | |
| // 計測終了 | |
| QueryPerformanceCounter(&b); | |
| // 差を求める | |
| diff.QuadPart = b.QuadPart - a.QuadPart; | |
| // 結果を表示 | |
| disp_large_int(freq); | |
| disp_large_int(a); | |
| disp_large_int(b); | |
| disp_large_int(diff); | |
| printf(" = %f seconds\n", (double) diff.QuadPart / freq.QuadPart); | |
| return 0; | |
| } | |
| /* 出力例: | |
| freq = 3215380 | |
| a = 331495678493 | |
| b = 331498893132 | |
| diff = 3214639 | |
| = 0.999770 seconds | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment