Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monokuma201607/b82f8fb7b73421a6c06c35c8686de482 to your computer and use it in GitHub Desktop.
Save monokuma201607/b82f8fb7b73421a6c06c35c8686de482 to your computer and use it in GitHub Desktop.
#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