123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- /*=============================================================================
- Copyright (c) 2010 Tim Blechmann
- Use, modification and distribution is subject to the Boost Software
- License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
- http://www.boost.org/LICENSE_1_0.txt)
- =============================================================================*/
- #include <iostream>
- #include <iomanip>
- #include "../../../boost/heap/d_ary_heap.hpp"
- #include "../../../boost/heap/pairing_heap.hpp"
- #include "../../../boost/heap/fibonacci_heap.hpp"
- #include "../../../boost/heap/binomial_heap.hpp"
- #include "../../../boost/heap/skew_heap.hpp"
- #include "heap_benchmarks.hpp"
- using namespace std;
- template <typename benchmark_selector>
- void run_benchmarks_immutable(void)
- {
- for (int i = 4; i != max_data; ++i) {
- for (int j = 0; j != 8; ++j) {
- int size = 1<<i;
- if (j%4 == 1)
- size += 1<<(i-3);
- if (j%4 == 2)
- size += 1<<(i-2);
- if (j%4 == 3)
- size += (1<<(i-3)) + (1<<(i-2));
- if (j >= 4)
- size += (1<<(i-1));
- cout << size << "\t";
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::binomial_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::fibonacci_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::pairing_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::skew_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::skew_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- cout << endl;
- }
- }
- }
- template <typename benchmark_selector>
- void run_benchmarks_mutable(void)
- {
- for (int i = 4; i != max_data; ++i)
- {
- for (int j = 0; j != 8; ++j)
- {
- int size = 1<<i;
- if (j%4 == 1)
- size += 1<<(i-3);
- if (j%4 == 2)
- size += 1<<(i-2);
- if (j%4 == 3)
- size += (1<<(i-3)) + (1<<(i-2));
- if (j >= 4)
- size += (1<<(i-1));
- cout << size << "\t";
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<2>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<4>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::d_ary_heap<long, boost::heap::arity<8>, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::binomial_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::fibonacci_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::pairing_heap<long> >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- {
- typedef typename benchmark_selector::
- template rebind<boost::heap::skew_heap<long, boost::heap::mutable_<true> > >
- ::type benchmark_functor;
- benchmark_functor benchmark(size);
- double result = run_benchmark(benchmark);
- cout << result << '\t';
- }
- cout << endl;
- }
- }
- }
- int main()
- {
- cout << fixed << setprecision(12);
- cout << "sequential push" << endl;
- run_benchmarks_immutable<make_sequential_push>();
- cout << endl << "sequential pop" << endl;
- run_benchmarks_immutable<make_sequential_pop>();
- cout << endl << "sequential increase" << endl;
- run_benchmarks_mutable<make_sequential_increase>();
- cout << endl << "sequential decrease" << endl;
- run_benchmarks_mutable<make_sequential_decrease>();
- cout << endl << "merge_and_clear" << endl;
- run_benchmarks_immutable<make_merge_and_clear>();
- cout << endl << "equivalence" << endl;
- run_benchmarks_immutable<make_equivalence>();
- }
|