Created
February 11, 2022 21:21
-
-
Save monokuma201607/b82f8fb7b73421a6c06c35c8686de482 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <Windows.h> | |
using namespace std; | |
void ex1(); | |
void ex2(); | |
void ex3(); | |
const int MAX = 100000000; | |
void ex1() { | |
// QueryPerformanceCounter関数の1秒当たりのカウント数を取得する | |
LARGE_INTEGER freq; | |
QueryPerformanceFrequency(&freq); | |
LARGE_INTEGER start, end; | |
vector<int> array; | |
QueryPerformanceCounter(&start); | |
array.reserve(MAX); | |
QueryPerformanceCounter(&end); | |
double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart; | |
printf("time %lf[ms]\n", time); | |
} | |
void ex2() { | |
LARGE_INTEGER freq; | |
QueryPerformanceFrequency(&freq); | |
LARGE_INTEGER start, end; | |
vector<int> array; | |
QueryPerformanceCounter(&start); | |
for (int i = 0; i < MAX; ++i) { | |
array.push_back(i); | |
} | |
QueryPerformanceCounter(&end); | |
double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart; | |
printf("time %lf[ms]\n", time); | |
} | |
void ex3() { | |
LARGE_INTEGER freq; | |
QueryPerformanceFrequency(&freq); | |
LARGE_INTEGER start, end; | |
vector<int> array; | |
QueryPerformanceCounter(&start); | |
array.reserve(MAX); | |
fill(array.begin(), array.end(), 1); | |
QueryPerformanceCounter(&end); | |
double time = static_cast<double>(end.QuadPart - start.QuadPart) * 1000.0 / freq.QuadPart; | |
printf("time %lf[ms]\n", time); | |
} | |
int main() | |
{ | |
printf("ex1\n"); | |
ex1(); | |
printf("ex2\n"); | |
ex2(); | |
printf("ex3\n"); | |
ex3(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment