adrienbrody2011

Performance check with test (C++)

May 10th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <ctime>
  4. #include <algorithm>
  5.  
  6. int Rand() {
  7.     return (rand() << 16) + rand();
  8. }
  9.  
  10. const int SIZE = 10000000;
  11. int num[SIZE];
  12.  
  13. int main() {
  14.     freopen("d:\\input.txt", "w", stdout);
  15.     int res_time = 0;
  16.     srand(time(0));
  17.     const int TIMES = 1;
  18.     for (int i = 0; i < TIMES; i++) {
  19.         for (int j = 0; j < SIZE; j++) {
  20.             int cur_num = Rand();
  21.             num[j] = cur_num;
  22.             printf("%d\n", cur_num);
  23.         }
  24.         clock_t s_time = clock();
  25.         std::sort(num, num + SIZE);
  26.         clock_t t_time = clock();
  27.         res_time += t_time - s_time;
  28.     }
  29.     freopen("d:\\time.txt", "w", stdout);
  30.     printf("C++: %.2f\n", (double)res_time / TIMES / CLOCKS_PER_SEC);
  31. }
Advertisement
Add Comment
Please, Sign In to add comment