using boost::timer::nanosecond_type;
#include "order_type.hpp"
+#include "random_shuffle.hpp"
//#define BOOST_MOVE_ADAPTIVE_SORT_STATS
+//#define BOOST_MOVE_ADAPTIVE_SORT_INVARIANTS
void print_stats(const char *str, boost::ulong_long_type element_count)
{
- std::printf("%sCmp:%7.03f Cpy:%8.03f\n", str, double(order_type::num_compare)/element_count, double(order_type::num_copy)/element_count );
+ std::printf("%sCmp:%7.03f Cpy:%8.03f\n", str, double(order_perf_type::num_compare)/element_count, double(order_perf_type::num_copy)/element_count );
}
#include <boost/move/algo/adaptive_sort.hpp>
#include <boost/move/algo/detail/merge_sort.hpp>
-#include <boost/move/algo/detail/bufferless_merge_sort.hpp>
#include <boost/move/core.hpp>
template<class T>
std::size_t key = key_len ? (i % key_len) : i;
elements[i].key=key;
}
- std::random_shuffle(elements, elements + element_count);
- std::random_shuffle(elements, elements + element_count);
- std::random_shuffle(elements, elements + element_count);
+ ::random_shuffle(elements, elements + element_count);
+ ::random_shuffle(elements, elements + element_count);
+ ::random_shuffle(elements, elements + element_count);
for(std::size_t i = 0; i < element_count; ++i){
elements[i].val = key_reps[elements[i].key]++;
}
SqrtAdaptiveSort,
Sqrt2AdaptiveSort,
QuartAdaptiveSort,
- NoBufMergeSort,
InplaceStableSort,
SlowStableSort,
HeapSort,
, "SqrtAdaptSort "
, "Sqrt2AdaptSort "
, "QuartAdaptSort "
- , "NoBufMergeSort "
, "InplStableSort "
, "SlowSort "
, "HeapSort "
generate_elements(elements, element_count, key_reps, key_len);
std::printf("%s ", AlgoNames[alg]);
- order_type::num_compare=0;
- order_type::num_copy=0;
- order_type::num_elements = element_count;
+ order_perf_type::num_compare=0;
+ order_perf_type::num_copy=0;
+ order_perf_type::num_elements = element_count;
cpu_timer timer;
timer.resume();
switch(alg)
{
case MergeSort:
- merge_sort_buffered(elements, element_count, order_type_less<T>());
+ merge_sort_buffered(elements, element_count, order_type_less());
break;
case StableSort:
- std::stable_sort(elements,elements+element_count,order_type_less<T>());
+ std::stable_sort(elements,elements+element_count,order_type_less());
break;
case AdaptiveSort:
- boost::movelib::adaptive_sort(elements, elements+element_count, order_type_less<T>());
+ boost::movelib::adaptive_sort(elements, elements+element_count, order_type_less());
break;
case SqrtHAdaptiveSort:
- adaptive_sort_buffered( elements, element_count, order_type_less<T>()
+ adaptive_sort_buffered( elements, element_count, order_type_less()
, boost::movelib::detail_adaptive::ceil_sqrt_multiple(element_count)/2+1);
break;
case SqrtAdaptiveSort:
- adaptive_sort_buffered( elements, element_count, order_type_less<T>()
+ adaptive_sort_buffered( elements, element_count, order_type_less()
, boost::movelib::detail_adaptive::ceil_sqrt_multiple(element_count));
break;
case Sqrt2AdaptiveSort:
- adaptive_sort_buffered( elements, element_count, order_type_less<T>()
+ adaptive_sort_buffered( elements, element_count, order_type_less()
, 2*boost::movelib::detail_adaptive::ceil_sqrt_multiple(element_count));
break;
case QuartAdaptiveSort:
- adaptive_sort_buffered( elements, element_count, order_type_less<T>()
+ adaptive_sort_buffered( elements, element_count, order_type_less()
, (element_count-1)/4+1);
break;
- case NoBufMergeSort:
- boost::movelib::bufferless_merge_sort(elements, elements+element_count, order_type_less<T>());
- break;
case InplaceStableSort:
- boost::movelib::inplace_stable_sort(elements, elements+element_count, order_type_less<T>());
+ boost::movelib::inplace_stable_sort(elements, elements+element_count, order_type_less());
break;
case SlowStableSort:
- boost::movelib::detail_adaptive::slow_stable_sort(elements, elements+element_count, order_type_less<T>());
+ boost::movelib::detail_adaptive::slow_stable_sort(elements, elements+element_count, order_type_less());
break;
case HeapSort:
- std::make_heap(elements, elements+element_count, order_type_less<T>());
- std::sort_heap(elements, elements+element_count, order_type_less<T>());
+ std::make_heap(elements, elements+element_count, order_type_less());
+ std::sort_heap(elements, elements+element_count, order_type_less());
break;
}
timer.stop();
- if(order_type::num_elements == element_count){
+ if(order_perf_type::num_elements == element_count){
std::printf(" Tmp Ok ");
} else{
std::printf(" Tmp KO ");
}
nanosecond_type new_clock = timer.elapsed().wall;
- //std::cout << "Cmp:" << order_type::num_compare << " Cpy:" << order_type::num_copy; //for old compilers without ll size argument
- std::printf("Cmp:%7.03f Cpy:%8.03f", double(order_type::num_compare)/element_count, double(order_type::num_copy)/element_count );
+ //std::cout << "Cmp:" << order_perf_type::num_compare << " Cpy:" << order_perf_type::num_copy; //for old compilers without ll size argument
+ std::printf("Cmp:%7.03f Cpy:%8.03f", double(order_perf_type::num_compare)/element_count, double(order_perf_type::num_copy)/element_count );
double time = double(new_clock);
, units
, prev_clock ? double(new_clock)/double(prev_clock): 1.0);
prev_clock = new_clock;
- bool res = is_order_type_ordered(elements, element_count, alg != HeapSort && alg != NoBufMergeSort);
+ bool res = is_order_type_ordered(elements, element_count, alg != HeapSort);
return res;
}
prev_clock = back_clock;
res = res && measure_algo(A,Keys,L,NK,InplaceStableSort, prev_clock);
//
- prev_clock = back_clock;
- res = res && measure_algo(A,Keys,L,NK,NoBufMergeSort, prev_clock);
- //
//prev_clock = back_clock;
//res = res && measure_algo(A,Keys,L,NK,SlowStableSort, prev_clock);
//
int main()
{
#ifndef BENCH_SORT_UNIQUE_VALUES
- //measure_all<order_type>(101,1);
- measure_all<order_type>(101,7);
- measure_all<order_type>(101,31);
+ measure_all<order_perf_type>(101,1);
+ measure_all<order_perf_type>(101,7);
+ measure_all<order_perf_type>(101,31);
#endif
- measure_all<order_type>(101,0);
+ measure_all<order_perf_type>(101,0);
//
#ifndef BENCH_SORT_UNIQUE_VALUES
- measure_all<order_type>(1101,1);
- measure_all<order_type>(1001,7);
- measure_all<order_type>(1001,31);
- measure_all<order_type>(1001,127);
- measure_all<order_type>(1001,511);
+ measure_all<order_perf_type>(1101,1);
+ measure_all<order_perf_type>(1001,7);
+ measure_all<order_perf_type>(1001,31);
+ measure_all<order_perf_type>(1001,127);
+ measure_all<order_perf_type>(1001,511);
#endif
- measure_all<order_type>(1001,0);
+ measure_all<order_perf_type>(1001,0);
//
#ifndef BENCH_SORT_SHORT
#ifndef BENCH_SORT_UNIQUE_VALUES
- measure_all<order_type>(10001,65);
- measure_all<order_type>(10001,255);
- measure_all<order_type>(10001,1023);
- measure_all<order_type>(10001,4095);
- measure_all<order_type>(10001,0);
+ measure_all<order_perf_type>(10001,65);
+ measure_all<order_perf_type>(10001,255);
+ measure_all<order_perf_type>(10001,1023);
+ measure_all<order_perf_type>(10001,4095);
#endif
+ measure_all<order_perf_type>(10001,0);
//
#ifndef BENCH_SORT_UNIQUE_VALUES
- measure_all<order_type>(100001,511);
- measure_all<order_type>(100001,2047);
- measure_all<order_type>(100001,8191);
- measure_all<order_type>(100001,32767);
+ measure_all<order_perf_type>(100001,511);
+ measure_all<order_perf_type>(100001,2047);
+ measure_all<order_perf_type>(100001,8191);
+ measure_all<order_perf_type>(100001,32767);
#endif
- measure_all<order_type>(100001,0);
+ measure_all<order_perf_type>(100001,0);
//
- //#ifdef NDEBUG
+ #ifdef NDEBUG
#ifndef BENCH_SORT_UNIQUE_VALUES
- measure_all<order_type>(1000001,1);
- measure_all<order_type>(1000001,1024);
- measure_all<order_type>(1000001,32768);
- measure_all<order_type>(1000001,524287);
+ measure_all<order_perf_type>(1000001,1);
+ measure_all<order_perf_type>(1000001,1024);
+ measure_all<order_perf_type>(1000001,32768);
+ measure_all<order_perf_type>(1000001,524287);
#endif
- measure_all<order_type>(1000001,0);
- measure_all<order_type>(1500001,0);
- //measure_all<order_type>(10000001,0);
- //#endif //NDEBUG
+ measure_all<order_perf_type>(1000001,0);
+ measure_all<order_perf_type>(1500001,0);
+ #endif //NDEBUG
#endif //#ifndef BENCH_SORT_SHORT
- //measure_all<order_type>(100000001,0);
+ //measure_all<order_perf_type>(100000001,0);
return 0;
}