fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef chrono::high_resolution_clock Clock_t;
  6. typedef chrono::milliseconds Time_scale_t;
  7.  
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  11.  
  12. mt19937_64 random;
  13.  
  14. for(int k = 15; k <= 22; k++)
  15. {
  16. size_t n = 1 << k; multiset<int> x; vector<int> a(n);
  17.  
  18. for(int i = 0; i < n; i++)
  19. x.insert(1+random()%100000);
  20.  
  21. auto start_time = Clock_t::now(); int j = 0;
  22.  
  23. // copying the multiset x to vector a
  24.  
  25. for(auto b:x)
  26. a[j++] = b;
  27.  
  28. auto duration = Clock_t::now() - start_time;
  29.  
  30. assert( is_sorted(a.begin(),a.end()) );
  31.  
  32. auto elapsed_time = chrono::duration_cast<Time_scale_t>(duration).count();
  33.  
  34. cout << "pow(2," << k << ") = " << n << " items: " << elapsed_time << " msec\n";
  35. }
  36. }
Success #stdin #stdout 9.24s 228288KB
stdin
Standard input is empty
stdout
pow(2,15) = 32768 items: 0 msec
pow(2,16) = 65536 items: 1 msec
pow(2,17) = 131072 items: 2 msec
pow(2,18) = 262144 items: 20 msec
pow(2,19) = 524288 items: 44 msec
pow(2,20) = 1048576 items: 95 msec
pow(2,21) = 2097152 items: 216 msec
pow(2,22) = 4194304 items: 433 msec