|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Benchmark Aleph-w binary search trees (timed insert/remove + height/IPL across powers of 2). More...
#include <gsl/gsl_rng.h>#include <cmath>#include <cstring>#include <algorithm>#include <array>#include <chrono>#include <iostream>#include <limits>#include <tuple>#include <vector>#include <tpl_binNodeUtils.H>#include <tpl_sort_utils.H>#include <tpl_binTree.H>#include <tpl_avl.H>#include <tpl_treap.H>#include <tpl_treapRk.H>#include <tpl_avlRk.H>#include <tpl_splay_tree.H>#include <tpl_splay_treeRk.H>#include <tpl_rb_tree.H>#include <tpl_rbRk.H>#include <tpl_tdRbTree.H>#include <tpl_tdRbTreeRk.H>#include <tpl_rand_tree.H>#include <tpl_dynMapTree.H>#include <argp.h>Go to the source code of this file.
Classes | |
| struct | Cmp_Sample< Key > |
| struct | TreeBenchmark |
| struct | Parameters |
Typedefs | |
| typedef tuple< double, double, double, double, double > | Stat |
| typedef tuple< int, double > | Sample |
Enumerations | |
| enum class | TreeType { BIN , AVL , AVL_RK , SPLAY , SPLAY_RK , TREAP , TREAP_RK , RB , RB_RK , TD_RB , TD_RB_RK , RAND } |
| enum | OptionKey { OPT_ALL = 'l' , OPT_AVL_RK = 1000 , OPT_SPLAY_RK , OPT_TREAP_RK , OPT_RB_RK , OPT_TD_RB , OPT_TD_RB_RK } |
Functions | |
| template<class Node > | |
| static void | printNode (Node *node, int, int) |
| bool | is_two_power (const unsigned int x) |
| template<template< typename, class > class TreeType, typename Key , class Compare = Aleph::less<Key>> | |
| tuple< Stat, Stat, int, int > | sample_tree (TreeType< Key, Compare > &tree, gsl_rng *r, int n, int k) |
| template<template< typename, class > class TreeType> | |
| void | test (unsigned long n, gsl_rng *r) |
| template<template< typename, class > class Tree> | |
| void | run_tree (unsigned long n, gsl_rng *r) |
| static const TreeBenchmark * | find_benchmark (TreeType type) |
| static error_t | parser_opt (int key, char *, struct argp_state *state) |
| int | main (int argc, char *argv[]) |
Variables | |
| constexpr int | Num_Samples = 37 |
| static const std::array< TreeBenchmark, 12 > | kBenchmarks |
| const char * | argp_program_version = "timeAllTree 0.0" |
| const char * | argp_program_bug_address = "lrleon@lavabit.com" |
| static char | doc [] = "timeAllTree -- Benchmark Aleph tree implementations" |
| static char | argDoc [] = "-n num_nodes -m seed_for_random [tree options]\n" |
| static struct argp_option | options [] |
| static struct argp | argDefs = {options, parser_opt, argDoc, doc, 0, 0, 0} |
Benchmark Aleph-w binary search trees (timed insert/remove + height/IPL across powers of 2).
This program benchmarks several Aleph-w binary search tree implementations by growing a tree up to n inserted keys and sampling performance at sizes 2^k.
At each sampled size it reports:
The benchmark is meant for comparative evaluation across tree types, not as a micro-benchmarking framework.
gsl_rng_mt19937).Tree<int, Aleph::less<int>>.You can benchmark individual implementations by selecting them with CLI flags:
--bin / -b: unbalanced BST (BinTree)--avl / -a: AVL (Avl_Tree)--avlrk: AVL ranked (Avl_Tree_Rk)--redblack / -r: RB (Rb_Tree)--redblackrk: RB ranked (Rb_Tree_Rk)--tdrb: top-down RB (TdRbTree)--tdrbrk: top-down RB ranked (TdRbTreeRk)--splay / -s: splay (Splay_Tree)--splayrk: splay ranked (Splay_Tree_Rk)--treap / -p: treap (Treap)--treaprk: treap ranked (Treap_Rk)--rand / -d: randomized tree (Rand_Tree)Or you can benchmark all of them with --all / -l.
Options:
--nodes / -n <num_nodes>: number of inserted nodes (default 1000).--seed / -m <seed_for_random>: RNG seed (default time(0)).If no tree types are selected (and --all is not provided), the program aborts.
n.2^k, it measures:For each selected tree, it prints markers:
timeAllTree<...> n seed (start/end)and a table with columns:
2^k, n, h (height), ipc (IPL)[min ins med sigma max][min ins med sigma max]Running time is dominated by repeated insert/remove operations and depends on the selected tree type. Expected per-operation costs are typically:
O(log n)O(n) worst caseTotal benchmark cost is roughly proportional to:
log2(n))-lgsl -lgslcblas).chrono tick units as used in the program.dynset_trees.C (practical container usage)tpl_avl.H, tpl_rb_tree.H, tpl_splay_tree.H, tpl_treap.HDefinition in file timeAllTree.C.
| typedef tuple<int, double> Sample |
Definition at line 197 of file timeAllTree.C.
| typedef tuple<double, double, double, double, double> Stat |
Definition at line 195 of file timeAllTree.C.
| enum OptionKey |
| Enumerator | |
|---|---|
| OPT_ALL | |
| OPT_AVL_RK | |
| OPT_SPLAY_RK | |
| OPT_TREAP_RK | |
| OPT_RB_RK | |
| OPT_TD_RB | |
| OPT_TD_RB_RK | |
Definition at line 444 of file timeAllTree.C.
|
strong |
| Enumerator | |
|---|---|
| BIN | |
| AVL | |
| AVL_RK | |
| SPLAY | |
| SPLAY_RK | |
| TREAP | |
| TREAP_RK | |
| RB | |
| RB_RK | |
| TD_RB | |
| TD_RB_RK | |
| RAND | |
Definition at line 366 of file timeAllTree.C.
|
static |
Definition at line 413 of file timeAllTree.C.
References kBenchmarks, and Aleph::maps().
Referenced by main().
|
inline |
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 557 of file timeAllTree.C.
References AH_ERROR, argDefs, BIN, Aleph::DynList< T >::empty(), StlAlephIterator< SetName >::end(), find_benchmark(), kBenchmarks, Aleph::maps(), Parameters::n, Parameters::run_all, Parameters::seed, and Parameters::selected.
|
static |
Definition at line 480 of file timeAllTree.C.
References AVL, AVL_RK, BIN, Aleph::maps(), OPT_ALL, OPT_AVL_RK, OPT_RB_RK, OPT_SPLAY_RK, OPT_TD_RB, OPT_TD_RB_RK, OPT_TREAP_RK, RAND, RB, RB_RK, SPLAY, SPLAY_RK, TD_RB, TD_RB_RK, TREAP, and TREAP_RK.
Definition at line 182 of file timeAllTree.C.
References Aleph::maps().
| void run_tree | ( | unsigned long | n, |
| gsl_rng * | r | ||
| ) |
Definition at line 383 of file timeAllTree.C.
References Aleph::maps().
| tuple< Stat, Stat, int, int > sample_tree | ( | TreeType< Key, Compare > & | tree, |
| gsl_rng * | r, | ||
| int | n, | ||
| int | k | ||
| ) |
Definition at line 211 of file timeAllTree.C.
References Aleph::computeHeightRec(), Aleph::count(), Aleph::internal_path_length(), KEY, Aleph::maps(), Num_Samples, sqrt(), and Aleph::Tree.
Referenced by test().
| void test | ( | unsigned long | n, |
| gsl_rng * | r | ||
| ) |
Definition at line 318 of file timeAllTree.C.
References Aleph::destroyRec(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert(), is_two_power(), log(), Aleph::maps(), N, pow(), sample_tree(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search(), and Aleph::Tree.
Referenced by Polygon::contains_to(), demo_density(), demo_eulerian(), demo_eulerian_digraph(), demo_konigsberg(), demo_practical(), Aleph::Xml_Graph< GT, Node_Reader, Arc_Reader, Node_Writer, Arc_Writer >::read_graph(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
static |
Definition at line 555 of file timeAllTree.C.
Referenced by main().
Definition at line 442 of file timeAllTree.C.
| const char* argp_program_bug_address = "lrleon@lavabit.com" |
Definition at line 439 of file timeAllTree.C.
| const char* argp_program_version = "timeAllTree 0.0" |
Definition at line 438 of file timeAllTree.C.
|
static |
Definition at line 441 of file timeAllTree.C.
|
static |
Definition at line 396 of file timeAllTree.C.
Referenced by find_benchmark(), and main().
|
constexpr |
Definition at line 188 of file timeAllTree.C.
Referenced by sample_tree().
|
static |
Definition at line 455 of file timeAllTree.C.