fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <algorithm>
  4. #include <iomanip>
  5.  
  6. template<typename T>
  7. struct cmp_count
  8. {
  9. static unsigned int n;
  10.  
  11. bool operator()(const T& lhs, const T& rhs)
  12. {
  13. ++n;
  14. static std::less<T> less;
  15. return less(lhs,rhs);
  16. }
  17.  
  18. unsigned int count() const { return n; }
  19. void reset() { n = 0; }
  20. };
  21.  
  22. template<typename T>
  23. unsigned int cmp_count<T>::n = 0;
  24.  
  25. int main()
  26. {
  27. std::random_device rd;
  28. std::mt19937 rng(rd());
  29.  
  30. for (int i=1024; i<100*1024; i += 1024)
  31. {
  32. std::vector<int> arr;
  33. arr.reserve(i);
  34. std::generate_n(std::back_inserter(arr), arr.capacity(), rng);
  35.  
  36. cmp_count<int> cmp;
  37. std::make_heap(arr.begin(), arr.end(), cmp);
  38.  
  39. // report output and reset
  40. std::cout << std::setw(12) << i;
  41. std::cout << std::setw(12) << static_cast<unsigned int>(std::round(std::log2(i)*i));
  42. std::cout << std::setw(12) << 3*arr.size();
  43. std::cout << std::setw(12) << cmp.count() << '\n';
  44. cmp.reset();
  45. }
  46. return 0;
  47. }
Success #stdin #stdout 0.13s 3476KB
stdin
Standard input is empty
stdout
        1024       10240        3072        1676
        2048       22528        6144        3376
        3072       35589        9216        5055
        4096       49152       12288        6726
        5120       63088       15360        8403
        6144       77322       18432       10101
        7168       91803       21504       11798
        8192      106496       24576       13507
        9216      121374       27648       15196
       10240      136417       30720       16908
       11264      151607       33792       18581
       12288      166932       36864       20267
       13312      182380       39936       21953
       14336      197942       43008       23649
       15360      213610       46080       25335
       16384      229376       49152       27027
       17408      245235       52224       28706
       18432      261180       55296       30412
       19456      277208       58368       32107
       20480      293313       61440       33795
       21504      309492       64512       35474
       22528      325742       67584       37166
       23552      342059       70656       38843
       24576      358440       73728       40533
       25600      374883       76800       42223
       26624      391385       79872       43923
       27648      407943       82944       45631
       28672      424556       86016       47305
       29696      441223       89088       48981
       30720      457940       92160       50678
       31744      474706       95232       52354
       32768      491520       98304       54049
       33792      508380      101376       55757
       34816      525285      104448       57444
       35840      542234      107520       59144
       36864      559224      110592       60835
       37888      576256      113664       62510
       38912      593327      116736       64211
       39936      610438      119808       65878
       40960      627586      122880       67568
       41984      644771      125952       69270
       43008      661993      129024       70953
       44032      679249      132096       72645
       45056      696540      135168       74311
       46080      713865      138240       75975
       47104      731222      141312       77682
       48128      748611      144384       79363
       49152      766032      147456       81066
       50176      783484      150528       82748
       51200      800965      153600       84418
       52224      818477      156672       86097
       53248      836017      159744       87772
       54272      853586      162816       89468
       55296      871182      165888       91140
       56320      888806      168960       92816
       57344      906457      172032       94505
       58368      924134      175104       96189
       59392      941837      178176       97891
       60416      959566      181248       99552
       61440      977319      184320      101239
       62464      995098      187392      102918
       63488     1012900      190464      104567
       64512     1030726      193536      106251
       65536     1048576      196608      107914
       66560     1066449      199680      109618
       67584     1084344      202752      111307
       68608     1102262      205824      112994
       69632     1120202      208896      114676
       70656     1138164      211968      116364
       71680     1156147      215040      118055
       72704     1174151      218112      119725
       73728     1192176      221184      121432
       74752     1210222      224256      123109
       75776     1228288      227328      124762
       76800     1246373      230400      126439
       77824     1264479      233472      128137
       78848     1282604      236544      129829
       79872     1300748      239616      131511
       80896     1318911      242688      133212
       81920     1337092      245760      134899
       82944     1355293      248832      136589
       83968     1373511      251904      138254
       84992     1391747      254976      139959
       86016     1410002      258048      141638
       87040     1428273      261120      143337
       88064     1446563      264192      145034
       89088     1464869      267264      146725
       90112     1483192      270336      148406
       91136     1501532      273408      150099
       92160     1519889      276480      151800
       93184     1538262      279552      153487
       94208     1556652      282624      155185
       95232     1575057      285696      156861
       96256     1593479      288768      158567
       97280     1611916      291840      160272
       98304     1630368      294912      161962
       99328     1648836      297984      163648
      100352     1667319      301056      165341
      101376     1685818      304128      167034