Lolly 1.4.28
Loading...
Searching...
No Matches
lolly_tree_bench.cpp
Go to the documentation of this file.
1/** \file lolly_tree_bench.cpp
2 * \copyright GPLv3
3 * \details Benchmark for tree
4 * \author jingkaimori
5 * \date 2024
6 */
7
9#include <nanobench.h>
10
11static ankerl::nanobench::Bench bench;
12
13namespace lolly {
14extern void init_tbox ();
15} // namespace lolly
16
18
19static test_tree
20generate_test_tree (int i= 0, int d= 3) {
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}
30
31int
32main () {
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}
blackbox t[13]
The list class represents a linked list.
Definition list.hpp:48
static test_tree generate_test_tree(int i=0, int d=3)
lolly::data::lolly_tree< int > test_tree
static ankerl::nanobench::Bench bench
int main()
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()
string as_string(int16_t i)
Definition string.cpp:272