|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Comprehensive benchmark for Aleph-w sorting algorithms. More...
#include <iostream>#include <iomanip>#include <chrono>#include <string>#include <functional>#include <random>#include <tclap/CmdLine.h>#include <tpl_dynArray.H>#include <tpl_array.H>#include <tpl_dynDlist.H>#include <htlist.H>#include <tpl_sort_utils.H>#include <ahSort.H>Go to the source code of this file.
Classes | |
| struct | BenchmarkConfig |
| class | Timer |
| class | DataGenerator |
Functions | |
| template<typename T > | |
| void | to_dynlist (const DynArray< T > &arr, DynList< T > &list) |
| template<typename T > | |
| void | to_dyndlist (const DynArray< T > &arr, DynDlist< T > &list) |
| template<typename T > | |
| void | to_array (const DynArray< T > &src, Array< T > &dst) |
| void | print_header () |
| void | print_result (const string &algo, const string &dist, const string &container, double time_ms, bool ok) |
| void | print_separator () |
| void | benchmark_array_algorithms (const BenchmarkConfig &config, const string &dist_name, const DynArray< int > &source_data) |
| void | benchmark_contiguous_array (const BenchmarkConfig &config, const string &dist_name, const DynArray< int > &source_data) |
| void | benchmark_list_algorithms (const BenchmarkConfig &config, const string &dist_name, const DynArray< int > &source_data) |
| void | run_benchmarks (const BenchmarkConfig &config) |
| void | demonstrate_complexity (const BenchmarkConfig &base_config) |
| void | print_recommendations () |
| int | main (int argc, char *argv[]) |
Comprehensive benchmark for Aleph-w sorting algorithms.
This program benchmarks only Aleph-w sorting algorithms across different data distributions and Aleph-w container types. This helps understand which algorithm performs best for different scenarios and data structures. No std::sort is used; benchmarked data uses Aleph-w containers.
Different sorting algorithms have different performance characteristics:
| Distribution | Description | Best Algorithm | Why |
|---|---|---|---|
| Random | Uniformly distributed | introsort()/quicksort_op() | Fast average case |
| Sorted | Already ascending | insertion_sort() | O(n) for sorted data |
| Reverse | Descending order | introsort()/heapsort() | Guaranteed O(n log n) |
| Nearly Sorted | 5% elements swapped | insertion_sort() | Adaptive, O(n) |
| Few Unique | Only 10 distinct values | introsort()/quicksort_op() | Good partitioning |
| Sawtooth | Alternating runs | mergesort() | Exploits runs |
| Algorithm | Best | Average | Worst | Space | Stable |
|---|---|---|---|---|---|
| Selection | O(n²) | O(n²) | O(n²) | O(1) | No |
| Insertion | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Bubble | O(n) | O(n²) | O(n²) | O(1) | Yes |
| Shellsort | O(n log n) | O(n^1.3) | O(n²) | O(1) | No |
| Mergesort | O(n log n) | O(n log n) | O(n log n) | O(n) | Yes |
| Quicksort | O(n log n) | O(n log n) | O(n²) | O(log n) | No |
| Heapsort | O(n log n) | O(n log n) | O(n log n) | O(1) | No |
| Introsort | O(n log n) | O(n log n) | O(n log n) | O(log n) | No |
Definition in file sort_benchmark.C.
| void benchmark_array_algorithms | ( | const BenchmarkConfig & | config, |
| const string & | dist_name, | ||
| const DynArray< int > & | source_data | ||
| ) |
Definition at line 365 of file sort_benchmark.C.
References Aleph::bubble_sort(), Aleph::heapsort(), Aleph::insertion_sort(), Aleph::introsort(), Aleph::is_sorted(), Aleph::maps(), BenchmarkConfig::num_elements, print_result(), Aleph::quicksort_op(), BenchmarkConfig::run_slow_algorithms, Aleph::selection_sort(), and Aleph::shellsort().
Referenced by run_benchmarks().
| void benchmark_contiguous_array | ( | const BenchmarkConfig & | config, |
| const string & | dist_name, | ||
| const DynArray< int > & | source_data | ||
| ) |
Definition at line 426 of file sort_benchmark.C.
References Aleph::faster_heapsort(), Aleph::introsort(), Aleph::is_sorted(), Aleph::maps(), print_result(), Aleph::Array< T >::size(), and to_array().
Referenced by run_benchmarks().
| void benchmark_list_algorithms | ( | const BenchmarkConfig & | config, |
| const string & | dist_name, | ||
| const DynArray< int > & | source_data | ||
| ) |
Definition at line 460 of file sort_benchmark.C.
References Aleph::in_place_sort(), Aleph::insertion_sort(), Aleph::is_sorted(), Aleph::maps(), Aleph::mergesort(), BenchmarkConfig::num_elements, print_result(), Aleph::quicksort(), BenchmarkConfig::run_slow_algorithms, to_dyndlist(), and to_dynlist().
Referenced by run_benchmarks().
| void demonstrate_complexity | ( | const BenchmarkConfig & | base_config | ) |
Definition at line 569 of file sort_benchmark.C.
References Aleph::introsort(), Aleph::maps(), Aleph::mergesort(), Aleph::quicksort_op(), to_array(), and to_dynlist().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 649 of file sort_benchmark.C.
| void print_header | ( | ) |
Definition at line 333 of file sort_benchmark.C.
References Aleph::maps().
Referenced by demo_arena_growth(), demo_basic_operations(), demo_calculator(), demo_city_coordinates(), demo_convex_hull_cities(), demo_convex_hull_performance(), demo_coverage_area(), demo_department_codes(), demo_encoding_decoding(), demo_geometric_primitives(), demo_hash_dispatcher(), demo_integration(), demo_list_dynlist(), demo_log_buffer(), demo_map_transformations(), demo_memory_stats(), demo_modifiable_mapping(), demo_move_semantics(), demo_numeric_mapping(), demo_range_conversions(), demo_regions_menu(), demo_state_machine(), demo_structured_data(), demo_text_processor(), demo_triangulation_basic(), demo_triangulation_complex(), demo_tuple_conversions(), demo_variadic_constructor(), demo_variadic_dispatcher(), demo_variadic_packing(), demo_vector_dynarray(), demo_vector_dynlist(), example_backpressure(), example_basic_parallel(), example_batch_processing(), example_fire_and_forget(), example_load_shedding(), example_parallel_aggregations(), example_parallel_enumerate(), example_parallel_filter(), example_parallel_find(), example_parallel_fold(), example_parallel_map(), example_parallel_predicates(), example_parallel_sort(), example_parallel_zip(), example_performance(), example_performance_comparison(), example_variadic_zip(), and run_benchmarks().
| void print_recommendations | ( | ) |
Definition at line 636 of file sort_benchmark.C.
References Aleph::maps().
| void print_result | ( | const string & | algo, |
| const string & | dist, | ||
| const string & | container, | ||
| double | time_ms, | ||
| bool | ok | ||
| ) |
Definition at line 345 of file sort_benchmark.C.
References Aleph::maps().
Referenced by benchmark_array_algorithms(), benchmark_contiguous_array(), and benchmark_list_algorithms().
| void print_separator | ( | ) |
Definition at line 356 of file sort_benchmark.C.
References Aleph::maps().
Referenced by run_benchmarks().
| void run_benchmarks | ( | const BenchmarkConfig & | config | ) |
Definition at line 511 of file sort_benchmark.C.
References benchmark_array_algorithms(), benchmark_contiguous_array(), benchmark_list_algorithms(), DataGenerator::few_unique(), Aleph::maps(), DataGenerator::nearly_sorted(), BenchmarkConfig::num_elements, print_header(), print_separator(), DataGenerator::random(), BenchmarkConfig::run_slow_algorithms, DataGenerator::sawtooth(), BenchmarkConfig::seed, DataGenerator::sorted_asc(), DataGenerator::sorted_desc(), BenchmarkConfig::test_arrays, and BenchmarkConfig::test_lists.
Definition at line 322 of file sort_benchmark.C.
References Aleph::DynList< T >::append(), Aleph::DynList< T >::empty(), Aleph::maps(), and Aleph::DynArray< T >::size().
Referenced by benchmark_contiguous_array(), and demonstrate_complexity().
Definition at line 314 of file sort_benchmark.C.
References Aleph::DynDlist< T >::append(), Aleph::DynDlist< T >::empty(), and Aleph::DynArray< T >::size().
Referenced by benchmark_list_algorithms().
Definition at line 306 of file sort_benchmark.C.
References Aleph::DynList< T >::append(), Aleph::DynList< T >::empty(), and Aleph::DynArray< T >::size().
Referenced by benchmark_list_algorithms(), and demonstrate_complexity().