Advertisement
runewalsh

Кукаретики соснулей

Nov 24th, 2012
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. // qwe.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "windows.h"
  6.  
  7. class Timer
  8. {
  9. public:
  10.     void initialize()
  11.     {
  12.         QueryPerformanceFrequency(&qpcFreq);
  13.         invFreq = 1.0 / (double)qpcFreq.QuadPart;
  14.     }
  15.     double time()
  16.     {
  17.         LARGE_INTEGER counter;
  18.         QueryPerformanceCounter(&counter);
  19.         return (double)counter.QuadPart * invFreq;
  20.     }
  21. private:
  22.     LARGE_INTEGER qpcFreq;
  23.     double invFreq;
  24. };
  25.  
  26. Timer timer = Timer();
  27.  
  28. int _tmain(int argc, _TCHAR* argv[])
  29. {
  30.     timer.initialize();
  31.  
  32.     const int N_ELEMS = 1000 * 100500;
  33.     int* arr = new int[N_ELEMS];
  34.     for (int i = 0; i < N_ELEMS; i++)
  35.         arr[i] = 0;
  36.  
  37.     double time = timer.time();
  38.     for (int i = 0; i < N_ELEMS; i+=1)
  39.         arr[i]++;
  40.     printf("+=1: %lf s\n", timer.time() - time);
  41.    
  42.     time = timer.time();
  43.     for (int i = 0; i < N_ELEMS; i+=16)
  44.         arr[i]++;
  45.     printf("+=16: %lf s\n", timer.time() - time);
  46.  
  47.     time = timer.time();
  48.     for (int i = 0; i < N_ELEMS; i+=17)
  49.         arr[i]++;
  50.     printf("+=17: %lf s\n", timer.time() - time);
  51.  
  52.     delete[] arr;
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement