throughput_benchmarks.cpp 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*=============================================================================
  2. Copyright (c) 2010 Tim Blechmann
  3. Use, modification and distribution is subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt)
  6. =============================================================================*/
  7. #include <iostream>
  8. #include <iomanip>
  9. #include "../../../boost/heap/d_ary_heap.hpp"
  10. #include "../../../boost/heap/pairing_heap.hpp"
  11. #include "../../../boost/heap/fibonacci_heap.hpp"
  12. #include "../../../boost/heap/binomial_heap.hpp"
  13. #include "../../../boost/heap/skew_heap.hpp"
  14. #include "heap_benchmarks.hpp"
  15. using namespace std;
  16. template <typename benchmark_selector>
  17. void run_benchmarks_immutable(void)
  18. {
  19. for (int i = 4; i != max_data; ++i) {
  20. for (int j = 0; j != 8; ++j) {
  21. int size = 1<<i;
  22. if (j%4 == 1)
  23. size += 1<<(i-3);
  24. if (j%4 == 2)
  25. size += 1<<(i-2);
  26. if (j%4 == 3)
  27. size += (1<<(i-3)) + (1<<(i-2));
  28. if (j >= 4)
  29. size += (1<<(i-1));
  30. cout << size << "\t";
  31. {
  32. typedef typename benchmark_selector::
  33. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2> > >
  34. ::type benchmark_functor;
  35. benchmark_functor benchmark(size);
  36. double result = run_benchmark(benchmark);
  37. cout << result << '\t';
  38. }
  39. {
  40. typedef typename benchmark_selector::
  41. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2>, boost::heap::mutable_<true> > >
  42. ::type benchmark_functor;
  43. benchmark_functor benchmark(size);
  44. double result = run_benchmark(benchmark);
  45. cout << result << '\t';
  46. }
  47. {
  48. typedef typename benchmark_selector::
  49. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4> > >
  50. ::type benchmark_functor;
  51. benchmark_functor benchmark(size);
  52. double result = run_benchmark(benchmark);
  53. cout << result << '\t';
  54. }
  55. {
  56. typedef typename benchmark_selector::
  57. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4>, boost::heap::mutable_<true> > >
  58. ::type benchmark_functor;
  59. benchmark_functor benchmark(size);
  60. double result = run_benchmark(benchmark);
  61. cout << result << '\t';
  62. }
  63. {
  64. typedef typename benchmark_selector::
  65. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8> > >
  66. ::type benchmark_functor;
  67. benchmark_functor benchmark(size);
  68. double result = run_benchmark(benchmark);
  69. cout << result << '\t';
  70. }
  71. {
  72. typedef typename benchmark_selector::
  73. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8>, boost::heap::mutable_<true> > >
  74. ::type benchmark_functor;
  75. benchmark_functor benchmark(size);
  76. double result = run_benchmark(benchmark);
  77. cout << result << '\t';
  78. }
  79. {
  80. typedef typename benchmark_selector::
  81. template rebind<boost::heap::binomial_heap<long> >
  82. ::type benchmark_functor;
  83. benchmark_functor benchmark(size);
  84. double result = run_benchmark(benchmark);
  85. cout << result << '\t';
  86. }
  87. {
  88. typedef typename benchmark_selector::
  89. template rebind<boost::heap::fibonacci_heap<long> >
  90. ::type benchmark_functor;
  91. benchmark_functor benchmark(size);
  92. double result = run_benchmark(benchmark);
  93. cout << result << '\t';
  94. }
  95. {
  96. typedef typename benchmark_selector::
  97. template rebind<boost::heap::pairing_heap<long> >
  98. ::type benchmark_functor;
  99. benchmark_functor benchmark(size);
  100. double result = run_benchmark(benchmark);
  101. cout << result << '\t';
  102. }
  103. {
  104. typedef typename benchmark_selector::
  105. template rebind<boost::heap::skew_heap<long> >
  106. ::type benchmark_functor;
  107. benchmark_functor benchmark(size);
  108. double result = run_benchmark(benchmark);
  109. cout << result << '\t';
  110. }
  111. {
  112. typedef typename benchmark_selector::
  113. template rebind<boost::heap::skew_heap<long> >
  114. ::type benchmark_functor;
  115. benchmark_functor benchmark(size);
  116. double result = run_benchmark(benchmark);
  117. cout << result << '\t';
  118. }
  119. cout << endl;
  120. }
  121. }
  122. }
  123. template <typename benchmark_selector>
  124. void run_benchmarks_mutable(void)
  125. {
  126. for (int i = 4; i != max_data; ++i)
  127. {
  128. for (int j = 0; j != 8; ++j)
  129. {
  130. int size = 1<<i;
  131. if (j%4 == 1)
  132. size += 1<<(i-3);
  133. if (j%4 == 2)
  134. size += 1<<(i-2);
  135. if (j%4 == 3)
  136. size += (1<<(i-3)) + (1<<(i-2));
  137. if (j >= 4)
  138. size += (1<<(i-1));
  139. cout << size << "\t";
  140. {
  141. typedef typename benchmark_selector::
  142. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2>, boost::heap::mutable_<true> > >
  143. ::type benchmark_functor;
  144. benchmark_functor benchmark(size);
  145. double result = run_benchmark(benchmark);
  146. cout << result << '\t';
  147. }
  148. {
  149. typedef typename benchmark_selector::
  150. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4>, boost::heap::mutable_<true> > >
  151. ::type benchmark_functor;
  152. benchmark_functor benchmark(size);
  153. double result = run_benchmark(benchmark);
  154. cout << result << '\t';
  155. }
  156. {
  157. typedef typename benchmark_selector::
  158. template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8>, boost::heap::mutable_<true> > >
  159. ::type benchmark_functor;
  160. benchmark_functor benchmark(size);
  161. double result = run_benchmark(benchmark);
  162. cout << result << '\t';
  163. }
  164. {
  165. typedef typename benchmark_selector::
  166. template rebind<boost::heap::binomial_heap<long> >
  167. ::type benchmark_functor;
  168. benchmark_functor benchmark(size);
  169. double result = run_benchmark(benchmark);
  170. cout << result << '\t';
  171. }
  172. {
  173. typedef typename benchmark_selector::
  174. template rebind<boost::heap::fibonacci_heap<long> >
  175. ::type benchmark_functor;
  176. benchmark_functor benchmark(size);
  177. double result = run_benchmark(benchmark);
  178. cout << result << '\t';
  179. }
  180. {
  181. typedef typename benchmark_selector::
  182. template rebind<boost::heap::pairing_heap<long> >
  183. ::type benchmark_functor;
  184. benchmark_functor benchmark(size);
  185. double result = run_benchmark(benchmark);
  186. cout << result << '\t';
  187. }
  188. {
  189. typedef typename benchmark_selector::
  190. template rebind<boost::heap::skew_heap<long, boost::heap::mutable_<true> > >
  191. ::type benchmark_functor;
  192. benchmark_functor benchmark(size);
  193. double result = run_benchmark(benchmark);
  194. cout << result << '\t';
  195. }
  196. cout << endl;
  197. }
  198. }
  199. }
  200. int main()
  201. {
  202. cout << fixed << setprecision(12);
  203. cout << "sequential push" << endl;
  204. run_benchmarks_immutable<make_sequential_push>();
  205. cout << endl << "sequential pop" << endl;
  206. run_benchmarks_immutable<make_sequential_pop>();
  207. cout << endl << "sequential increase" << endl;
  208. run_benchmarks_mutable<make_sequential_increase>();
  209. cout << endl << "sequential decrease" << endl;
  210. run_benchmarks_mutable<make_sequential_decrease>();
  211. cout << endl << "merge_and_clear" << endl;
  212. run_benchmarks_immutable<make_merge_and_clear>();
  213. cout << endl << "equivalence" << endl;
  214. run_benchmarks_immutable<make_equivalence>();
  215. }