Advertisement
Morgan_iv

Untitled

Mar 30th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <vector>
  2. #include <algorithm>
  3. #include <cstdlib>
  4. #include <ctime>
  5. #include <chrono>
  6. #include <iostream>
  7.  
  8. using calctime_t = std::chrono::duration<long long, std::ratio<1, 10000000> >;
  9.  
  10. int main(int argc, char const *argv[])
  11. {
  12.     srand(time(NULL));
  13.     int count = 1000000;
  14.     std::vector<int64_t> vec(count);
  15.     for (int i = 0; i < count; ++i)
  16.     {
  17.         vec[i] = (rand() % 2000) - 1000;
  18.     }
  19.     auto start = std::chrono::steady_clock::now();
  20.  
  21.     std::sort(vec.begin(), vec.end());
  22.  
  23.     auto end = std::chrono::steady_clock::now();
  24.  
  25.     for (int i = 0; i < count; ++i)
  26.     {
  27.         std::cout << vec[i];
  28.     }
  29.  
  30.     calctime_t mtime = std::chrono::duration_cast<calctime_t>(end - start);
  31.  
  32.     std::cout << std::endl;
  33.     std::cout << "0.0" << mtime.count() << std::endl;
  34.  
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement