fork download
  1. #include <boost/heap/fibonacci_heap.hpp>
  2. #include <boost/heap/priority_queue.hpp>
  3. #include <boost/heap/binomial_heap.hpp>
  4. #include <boost/heap/d_ary_heap.hpp>
  5. #include <queue>
  6. #include <chrono>
  7. #include <iostream>
  8.  
  9. using namespace std;
  10. using namespace std::chrono;
  11.  
  12. int main(){
  13. std::priority_queue<int> pq;
  14. std::priority_queue<int, std::deque<int> > pqd;
  15. boost::heap::priority_queue<int> bpq;
  16. boost::heap::fibonacci_heap<int> bfh;
  17. boost::heap::binomial_heap<int> bbh;
  18.  
  19. const int NUM_ITER = 1000000;
  20.  
  21.  
  22. cout << "NUM_ITER:" << NUM_ITER << "\n";
  23. auto ts = system_clock::now();
  24. for(int i=0; i<NUM_ITER; i++){
  25. pq.push(rand());
  26. }
  27. for(int i=0; i<NUM_ITER; i++){
  28. pq.pop();
  29. }
  30. double ts1 = duration_cast<nanoseconds>(system_clock::now() - ts).count();
  31. cout << "std::priority_queue: " << ts1/(double)NUM_ITER << " ns\n";
  32.  
  33. ts = system_clock::now();
  34. for(int i=0; i<NUM_ITER; i++){
  35. pqd.push(rand());
  36. }
  37. for(int i=0; i<NUM_ITER; i++){
  38. pqd.pop();
  39. }
  40. ts1 = duration_cast<nanoseconds>(system_clock::now() - ts).count();
  41. cout << "std::priority_queue<int, std::deque<int> >: " << ts1/(double)NUM_ITER << " ns\n";
  42.  
  43. ts = system_clock::now();
  44. for(int i=0; i<NUM_ITER; i++){
  45. bpq.push(rand());
  46. }
  47. for(int i=0; i<NUM_ITER; i++){
  48. bpq.pop();
  49. }
  50. ts1 = duration_cast<nanoseconds>(system_clock::now() - ts).count();
  51. cout << "boost::heap::priority_queue: " << ts1/(double)NUM_ITER << " ns\n";
  52.  
  53. ts = system_clock::now();
  54. for(int i=0; i<NUM_ITER; i++){
  55. bfh.push(rand());
  56. }
  57. for(int i=0; i<NUM_ITER; i++){
  58. bfh.pop();
  59. }
  60. ts1 = duration_cast<nanoseconds>(system_clock::now() - ts).count();
  61. cout << "boost::heap::fibonacci_heap: " << ts1/(double)NUM_ITER << " ns\n";
  62.  
  63. ts = system_clock::now();
  64. for(int i=0; i<NUM_ITER; i++){
  65. bbh.push(rand());
  66. }
  67. for(int i=0; i<NUM_ITER; i++){
  68. bbh.pop();
  69. }
  70. ts1 = duration_cast<nanoseconds>(system_clock::now() - ts).count();
  71. cout << "boost::heap::binomial_heap: " << ts1/(double)NUM_ITER << " ns\n";
  72.  
  73. }
  74.  
Success #stdin #stdout 3.33s 89416KB
stdin
Standard input is empty
stdout
NUM_ITER:1000000
std::priority_queue: 144.905 ns
std::priority_queue<int, std::deque<int> >: 264.63 ns
boost::heap::priority_queue: 161.675 ns
boost::heap::fibonacci_heap: 954.02 ns
boost::heap::binomial_heap: 1620.58 ns