|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Comprehensive benchmark comparing all set data structures in Aleph-w. More...
#include <iostream>#include <iomanip>#include <chrono>#include <vector>#include <algorithm>#include <random>#include <string>#include <functional>#include <cmath>#include <set>#include <unordered_set>#include <tpl_dynSetTree.H>#include <tpl_dynSkipList.H>#include <tpl_dynSetHash.H>#include <tpl_odhash.H>#include <tpl_olhash.H>Go to the source code of this file.
Classes | |
| struct | BenchmarkResult |
Typedefs | |
| using | AvlSet = DynSetTree< int, Avl_Tree > |
| using | RbSet = DynSetTree< int, Rb_Tree > |
| using | SplaySet = DynSetTree< int, Splay_Tree > |
| using | TreapSet = DynSetTree< int, Treap > |
| using | RandSet = DynSetTree< int, Rand_Tree > |
| using | AvlRkSet = DynSetTree< int, Avl_Tree_Rk > |
| using | TreapRkSet = DynSetTree< int, Treap_Rk > |
| using | SkipSet = DynSkipList< int > |
| using | LhashSet = DynSetLhash< int > |
| using | LinHashSet = DynSetLinHash< int > |
| using | ODHashSet = SetODhash< int > |
| using | OLHashSet = SetOLhash< int > |
Functions | |
| template<typename Func > | |
| double | measure_ms (Func &&f) |
| template<typename Set > | |
| BenchmarkResult | benchmark_tree_set (const string &name, const string &category, const vector< int > &data) |
| template<typename Set > | |
| BenchmarkResult | benchmark_hash_set (const string &name, const string &category, const vector< int > &data) |
| BenchmarkResult | benchmark_skip_list (const string &name, const string &category, const vector< int > &data) |
| BenchmarkResult | benchmark_std_set (const string &name, const string &category, const vector< int > &data) |
| BenchmarkResult | benchmark_std_unordered_set (const string &name, const string &category, const vector< int > &data) |
| vector< int > | generate_random_data (size_t n, unsigned seed) |
| vector< int > | generate_sequential_data (size_t n) |
| void | print_results_table (const vector< BenchmarkResult > &results, size_t n) |
| void | print_operations_per_second (const vector< BenchmarkResult > &results, size_t n) |
| void | run_full_benchmark (size_t n, unsigned seed, bool include_ranked) |
| void | run_sequential_test (size_t n) |
| int | main (int argc, char *argv[]) |
Comprehensive benchmark comparing all set data structures in Aleph-w.
This benchmark compares performance of different set implementations available in Aleph-w. Understanding the performance characteristics of each structure helps choose the right one for your use case.
Different set structures have different performance characteristics:
| Structure | Insert | Search | Delete | Ordered? | Best For |
|---|---|---|---|---|---|
| AVL Tree | O(log n) | O(log n) | O(log n) | Yes | Read-heavy |
| Red-Black | O(log n) | O(log n) | O(log n) | Yes | General |
| Splay | O(log n)* | O(log n)* | O(log n)* | Yes | Temporal locality |
| Treap | O(log n)** | O(log n)** | O(log n)** | Yes | Simple |
| Skip List | O(log n)** | O(log n)** | O(log n)** | Yes | Simplicity |
| Hash Tables | O(1)** | O(1)** | O(1)** | No | Maximum speed |
| Structure | Best For | Avoid When |
|---|---|---|
| AVL/RB Tree | Ordered traversal, range queries, predictable O(log n) | Order not needed |
| Splay Tree | Temporal locality, caching patterns | Worst-case matters |
| Skip List | Simplicity, concurrent extensions | Deterministic needed |
| Hash Tables | Maximum speed, order doesn't matter | Ordered iteration needed |
| DynSetLhash | High load factors, many insertions/deletions | Memory critical |
| ODhash/OLhash | Memory efficiency, cache-friendly | Dynamic resizing needed |
| DynSetLinHash | Dynamic workloads, varying sizes | Fixed size preferred |
This benchmark measures:
Definition in file set_structures_benchmark.cc.
| using AvlRkSet = DynSetTree<int, Avl_Tree_Rk> |
Definition at line 210 of file set_structures_benchmark.cc.
| using AvlSet = DynSetTree<int, Avl_Tree> |
Definition at line 203 of file set_structures_benchmark.cc.
| using LhashSet = DynSetLhash<int> |
Definition at line 217 of file set_structures_benchmark.cc.
| using LinHashSet = DynSetLinHash<int> |
Definition at line 218 of file set_structures_benchmark.cc.
Definition at line 219 of file set_structures_benchmark.cc.
Definition at line 220 of file set_structures_benchmark.cc.
| using RandSet = DynSetTree<int, Rand_Tree> |
Definition at line 207 of file set_structures_benchmark.cc.
| using RbSet = DynSetTree<int, Rb_Tree> |
Definition at line 204 of file set_structures_benchmark.cc.
| using SkipSet = DynSkipList<int> |
Definition at line 214 of file set_structures_benchmark.cc.
| using SplaySet = DynSetTree<int, Splay_Tree> |
Definition at line 205 of file set_structures_benchmark.cc.
| using TreapRkSet = DynSetTree<int, Treap_Rk> |
Definition at line 211 of file set_structures_benchmark.cc.
| using TreapSet = DynSetTree<int, Treap> |
Definition at line 206 of file set_structures_benchmark.cc.
| BenchmarkResult benchmark_hash_set | ( | const string & | name, |
| const string & | category, | ||
| const vector< int > & | data | ||
| ) |
Definition at line 288 of file set_structures_benchmark.cc.
References BenchmarkResult::category, BenchmarkResult::insert_ms, Aleph::maps(), measure_ms(), BenchmarkResult::memory_hint, BenchmarkResult::name, BenchmarkResult::remove_ms, BenchmarkResult::search_ms, and BenchmarkResult::total_ms.
| BenchmarkResult benchmark_skip_list | ( | const string & | name, |
| const string & | category, | ||
| const vector< int > & | data | ||
| ) |
Definition at line 326 of file set_structures_benchmark.cc.
References BenchmarkResult::category, Aleph::DynSkipList< Key, Compare >::insert(), BenchmarkResult::insert_ms, Aleph::maps(), measure_ms(), BenchmarkResult::memory_hint, BenchmarkResult::name, Aleph::DynSkipList< Key, Compare >::remove(), BenchmarkResult::remove_ms, Aleph::DynSkipList< Key, Compare >::search(), BenchmarkResult::search_ms, and BenchmarkResult::total_ms.
Referenced by run_full_benchmark().
| BenchmarkResult benchmark_std_set | ( | const string & | name, |
| const string & | category, | ||
| const vector< int > & | data | ||
| ) |
Definition at line 364 of file set_structures_benchmark.cc.
References BenchmarkResult::category, BenchmarkResult::insert_ms, Aleph::maps(), measure_ms(), BenchmarkResult::memory_hint, BenchmarkResult::name, BenchmarkResult::remove_ms, BenchmarkResult::search_ms, and BenchmarkResult::total_ms.
Referenced by run_full_benchmark().
| BenchmarkResult benchmark_std_unordered_set | ( | const string & | name, |
| const string & | category, | ||
| const vector< int > & | data | ||
| ) |
Definition at line 402 of file set_structures_benchmark.cc.
References BenchmarkResult::category, BenchmarkResult::insert_ms, Aleph::maps(), measure_ms(), BenchmarkResult::memory_hint, BenchmarkResult::name, BenchmarkResult::remove_ms, BenchmarkResult::search_ms, and BenchmarkResult::total_ms.
Referenced by run_full_benchmark().
| BenchmarkResult benchmark_tree_set | ( | const string & | name, |
| const string & | category, | ||
| const vector< int > & | data | ||
| ) |
Definition at line 249 of file set_structures_benchmark.cc.
References BenchmarkResult::category, BenchmarkResult::insert_ms, Aleph::maps(), measure_ms(), BenchmarkResult::memory_hint, BenchmarkResult::name, BenchmarkResult::remove_ms, BenchmarkResult::search_ms, and BenchmarkResult::total_ms.
| vector< int > generate_random_data | ( | size_t | n, |
| unsigned | seed | ||
| ) |
Definition at line 443 of file set_structures_benchmark.cc.
References Aleph::maps(), rng, Aleph::shuffle(), Aleph::sort(), and Aleph::unique().
Referenced by run_full_benchmark().
| vector< int > generate_sequential_data | ( | size_t | n | ) |
Definition at line 463 of file set_structures_benchmark.cc.
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 678 of file set_structures_benchmark.cc.
| double measure_ms | ( | Func && | f | ) |
Definition at line 239 of file set_structures_benchmark.cc.
Referenced by benchmark_hash_set(), benchmark_skip_list(), benchmark_std_set(), benchmark_std_unordered_set(), and benchmark_tree_set().
| void print_operations_per_second | ( | const vector< BenchmarkResult > & | results, |
| size_t | n | ||
| ) |
Definition at line 520 of file set_structures_benchmark.cc.
References Aleph::maps().
Referenced by run_full_benchmark().
| void print_results_table | ( | const vector< BenchmarkResult > & | results, |
| size_t | n | ||
| ) |
Definition at line 476 of file set_structures_benchmark.cc.
References Aleph::DynList< T >::empty(), and Aleph::maps().
Referenced by run_full_benchmark().
| void run_full_benchmark | ( | size_t | n, |
| unsigned | seed, | ||
| bool | include_ranked | ||
| ) |
Definition at line 543 of file set_structures_benchmark.cc.
References benchmark_skip_list(), benchmark_std_set(), benchmark_std_unordered_set(), generate_random_data(), log2(), Aleph::maps(), print_operations_per_second(), print_results_table(), and Aleph::HTList::size().
| void run_sequential_test | ( | size_t | n | ) |
Definition at line 641 of file set_structures_benchmark.cc.