Lolly 1.4.28
Loading...
Searching...
No Matches
Namespaces | Typedefs | Functions | Variables
lolly_tree_bench.cpp File Reference
#include "lolly/data/lolly_tree.hpp"
#include <nanobench.h>
Include dependency graph for lolly_tree_bench.cpp:

Go to the source code of this file.

Namespaces

namespace  lolly
 

Typedefs

using test_tree = lolly::data::lolly_tree<int>
 

Functions

void lolly::init_tbox ()
 
static test_tree generate_test_tree (int i=0, int d=3)
 
int main ()
 

Variables

static ankerl::nanobench::Bench bench
 

Detailed Description

Benchmark for tree

Author
jingkaimori
Date
2024

Definition in file lolly_tree_bench.cpp.

Typedef Documentation

◆ test_tree

Definition at line 17 of file lolly_tree_bench.cpp.

Function Documentation

◆ generate_test_tree()

static test_tree generate_test_tree ( int i = 0,
int d = 3 )
static

Definition at line 20 of file lolly_tree_bench.cpp.

20 {
21 if (d == 0) return test_tree (as_string (i));
22 else {
23 int n= 6 + ((int) (2 * sin (1.0 * i * d)));
24 test_tree t (2, n);
25 for (int j= 0; j < n; i++, j++)
26 t[j]= test_tree (i, d - 1);
27 return t;
28 }
29}
blackbox t[13]
The list class represents a linked list.
Definition list.hpp:48
lolly::data::lolly_tree< int > test_tree
string as_string(int16_t i)
Definition string.cpp:272

◆ main()

int main ( )

Definition at line 32 of file lolly_tree_bench.cpp.

32 {
34#ifdef OS_WASM
35 bench.minEpochIterations (2000);
36#else
37 bench.minEpochIterations (200000);
38#endif
39 bench.complexityN (1).run ("construct atomic tree",
40 [&] { test_tree ("abc"); });
41 bench.run ("construct compound tree of depth from argument",
42 [&] { test_tree (10, "abc", "def", "ghi"); });
43 bench.run ("construct compound tree from array",
44 [&] { test_tree (10, array<test_tree> ("abc", "def", "ghi")); });
45 for (int d= 1; d < 6; d++) {
46 bench.complexityN (d);
47 bench.run ("construct compound tree of given depth",
48 [&] { generate_test_tree (0, d); });
49 }
50 for (int d= 1; d < 6; d++) {
51 static test_tree tr= generate_test_tree (0, d);
52 bench.complexityN (d).run ("type of tree",
53 [&] { lolly::data::is_compound (tr); });
54 }
55 for (int d= 1; d < 6; d++) {
56 static test_tree tr= generate_test_tree (0, d);
57 bench.complexityN (d).run ("size of tree", [&] { lolly::data::N (tr); });
58 }
59 for (int d= 1; d < 6; d++) {
60 static test_tree tr= generate_test_tree (0, d);
61 bench.complexityN (d).run ("immutable index of tree",
62 [&] { lolly::data::A (tr)[0]; });
63 }
64 for (int d= 1; d < 6; d++) {
65 static test_tree tr= generate_test_tree (0, d);
66 bench.complexityN (d).run ("mutable index of tree",
67 [&] { lolly::data::AR (tr)[0]= "abcdef"; });
68 }
69 for (int d= 1; d < 6; d++) {
70 static test_tree tr= generate_test_tree (0, d);
71 bench.complexityN (d).run ("copy tree", [&] { lolly::data::copy (tr); });
72 }
73 for (int d= 1; d < 6; d++) {
74 static test_tree tr1= generate_test_tree (0, d),
76 bench.complexityN (d).run ("equality of tree", [&] { tr1 == tr2; });
77 }
78}
static test_tree generate_test_tree(int i=0, int d=3)
static ankerl::nanobench::Bench bench
array< lolly_tree< T > > A(lolly_tree< T > t)
array< lolly_tree< T > > & AR(lolly_tree< T > t)
bool is_compound(lolly_tree< T > t)
int N(lolly_tree< T > t)
lolly_tree< T > copy(lolly_tree< T > t)
void init_tbox()

Variable Documentation

◆ bench

Definition at line 11 of file lolly_tree_bench.cpp.