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. for (int i=1024; i<100*1024; i += 1024)
  28. {
  29. std::vector<int> arr;
  30. arr.reserve(i);
  31. std::generate_n(std::back_inserter(arr), arr.capacity(),
  32. [](){ static int i=0; return ++i;});
  33.  
  34. cmp_count<int> cmp;
  35. std::make_heap(arr.begin(), arr.end(), cmp);
  36.  
  37. // report output and reset
  38. std::cout << std::setw(12) << i;
  39. std::cout << std::setw(12) << static_cast<unsigned int>(std::round(std::log2(i)*i));
  40. std::cout << std::setw(12) << 3*arr.size();
  41. std::cout << std::setw(12) << cmp.count() << '\n';
  42. cmp.reset();
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0.06s 3472KB
stdin
Standard input is empty
stdout
        1024       10240        3072        1525
        2048       22528        6144        3060
        3072       35589        9216        4595
        4096       49152       12288        6131
        5120       63088       15360        7667
        6144       77322       18432        9202
        7168       91803       21504       10738
        8192      106496       24576       12274
        9216      121374       27648       13811
       10240      136417       30720       15346
       11264      151607       33792       16882
       12288      166932       36864       18417
       13312      182380       39936       19954
       14336      197942       43008       21489
       15360      213610       46080       23025
       16384      229376       49152       24561
       17408      245235       52224       26099
       18432      261180       55296       27634
       19456      277208       58368       29170
       20480      293313       61440       30705
       21504      309492       64512       32242
       22528      325742       67584       33777
       23552      342059       70656       35313
       24576      358440       73728       36848
       25600      374883       76800       38386
       26624      391385       79872       39921
       27648      407943       82944       41457
       28672      424556       86016       42992
       29696      441223       89088       44529
       30720      457940       92160       46064
       31744      474706       95232       47600
       32768      491520       98304       49136
       33792      508380      101376       50675
       34816      525285      104448       52210
       35840      542234      107520       53746
       36864      559224      110592       55281
       37888      576256      113664       56818
       38912      593327      116736       58353
       39936      610438      119808       59889
       40960      627586      122880       61424
       41984      644771      125952       62962
       43008      661993      129024       64497
       44032      679249      132096       66033
       45056      696540      135168       67568
       46080      713865      138240       69105
       47104      731222      141312       70640
       48128      748611      144384       72176
       49152      766032      147456       73711
       50176      783484      150528       75250
       51200      800965      153600       76785
       52224      818477      156672       78321
       53248      836017      159744       79856
       54272      853586      162816       81393
       55296      871182      165888       82928
       56320      888806      168960       84464
       57344      906457      172032       85999
       58368      924134      175104       87537
       59392      941837      178176       89072
       60416      959566      181248       90608
       61440      977319      184320       92143
       62464      995098      187392       93680
       63488     1012900      190464       95215
       64512     1030726      193536       96751
       65536     1048576      196608       98287
       66560     1066449      199680       99827
       67584     1084344      202752      101362
       68608     1102262      205824      102898
       69632     1120202      208896      104433
       70656     1138164      211968      105970
       71680     1156147      215040      107505
       72704     1174151      218112      109041
       73728     1192176      221184      110576
       74752     1210222      224256      112114
       75776     1228288      227328      113649
       76800     1246373      230400      115185
       77824     1264479      233472      116720
       78848     1282604      236544      118257
       79872     1300748      239616      119792
       80896     1318911      242688      121328
       81920     1337092      245760      122863
       82944     1355293      248832      124402
       83968     1373511      251904      125937
       84992     1391747      254976      127473
       86016     1410002      258048      129008
       87040     1428273      261120      130545
       88064     1446563      264192      132080
       89088     1464869      267264      133616
       90112     1483192      270336      135151
       91136     1501532      273408      136689
       92160     1519889      276480      138224
       93184     1538262      279552      139760
       94208     1556652      282624      141295
       95232     1575057      285696      142832
       96256     1593479      288768      144367
       97280     1611916      291840      145903
       98304     1630368      294912      147438
       99328     1648836      297984      148978
      100352     1667319      301056      150513
      101376     1685818      304128      152049