fork download
  1. #include <vector>
  2. #include <chrono>
  3. #include <random>
  4. #include <cstdlib>
  5. #include <iostream>
  6. #include <algorithm>
  7.  
  8. int compare (const void * a, const void * b)
  9. {
  10. return ( *(int*)a - *(int*)b );
  11. }
  12.  
  13.  
  14. int main() {
  15. std::vector<int> values;
  16. values.reserve(100000);
  17. std::random_device rd;
  18. std::uniform_int_distribution<int> dist;
  19. std::mt19937 eng(rd());
  20. for(std::size_t i=0; i!=100000; ++i) {
  21. values.push_back(dist(eng));
  22. }
  23. std::vector<int> values2(values);
  24.  
  25. {
  26. auto n=std::chrono::high_resolution_clock::now();
  27. std::qsort (values.data(), values.size(), sizeof(int), compare);
  28. auto t=std::chrono::high_resolution_clock::now() - n;
  29. std::cout << t.count() << std::endl;
  30. }
  31. {
  32. auto n=std::chrono::high_resolution_clock::now();
  33.  
  34. std::sort(values2.begin(), values2.end());
  35.  
  36. auto t=std::chrono::high_resolution_clock::now() - n;
  37. std::cout << t.count() << std::endl;
  38. }
  39.  
  40. }
Runtime error #stdin #stdout 0s 3452KB
stdin
Standard input is empty
stdout

Standard output is empty