Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // qwe.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include "windows.h"
- class Timer
- {
- public:
- void initialize()
- {
- QueryPerformanceFrequency(&qpcFreq);
- invFreq = 1.0 / (double)qpcFreq.QuadPart;
- }
- double time()
- {
- LARGE_INTEGER counter;
- QueryPerformanceCounter(&counter);
- return (double)counter.QuadPart * invFreq;
- }
- private:
- LARGE_INTEGER qpcFreq;
- double invFreq;
- };
- Timer timer = Timer();
- int _tmain(int argc, _TCHAR* argv[])
- {
- timer.initialize();
- const int N_ELEMS = 1000 * 100500;
- int* arr = new int[N_ELEMS];
- for (int i = 0; i < N_ELEMS; i++)
- arr[i] = 0;
- double time = timer.time();
- for (int i = 0; i < N_ELEMS; i+=1)
- arr[i]++;
- printf("+=1: %lf s\n", timer.time() - time);
- time = timer.time();
- for (int i = 0; i < N_ELEMS; i+=16)
- arr[i]++;
- printf("+=16: %lf s\n", timer.time() - time);
- time = timer.time();
- for (int i = 0; i < N_ELEMS; i+=17)
- arr[i]++;
- printf("+=17: %lf s\n", timer.time() - time);
- delete[] arr;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement