Lolly 1.4.28
Loading...
Searching...
No Matches
Classes | Functions | Variables
fast_alloc_bench.cpp File Reference
#include "fast_alloc.hpp"
#include "sys_utils.hpp"
#include <nanobench.h>
Include dependency graph for fast_alloc_bench.cpp:

Go to the source code of this file.

Classes

struct  Complex
 

Functions

int main ()
 

Variables

static ankerl::nanobench::Bench bench
 

Detailed Description

Benchmark for memory allocator

Author
jingkaimori
Date
2024

Definition in file fast_alloc_bench.cpp.

Function Documentation

◆ main()

int main ( )

Definition at line 22 of file fast_alloc_bench.cpp.

22 {
24
25#ifdef OS_WASM
26 constexpr int NUM= 100;
27#else
28 constexpr int NUM = 10000;
29#endif
30
31 char* ch[NUM];
32 int* in[NUM];
33 long* lo[NUM];
34 double* dou[NUM];
35
36 bench.batch (NUM * 4)
37 .unit ("alloc & free")
38 .run ("basic type, fast collect", [&] {
39 for (int i= 0; i < NUM; i++) { // for gprof
40 ch[i]= tm_new<char> ();
41 tm_delete (ch[i]);
42
43 in[i]= tm_new<int> ();
44 tm_delete (in[i]);
45
46 lo[i]= tm_new<long> ();
47 tm_delete (lo[i]);
48
49 dou[i]= tm_new<double> ();
50 tm_delete (dou[i]);
51 }
52 });
53
54 bench.run ("basic type, bulk collect", [&] {
55 for (int i= 0; i < NUM; i++) {
56 ch[i] = tm_new<char> ();
57 in[i] = tm_new<int> ();
58 lo[i] = tm_new<long> ();
59 dou[i]= tm_new<double> ();
60 }
61
62 for (int i= 0; i < NUM; i++) {
63 tm_delete (ch[i]);
64 tm_delete (in[i]);
65 tm_delete (lo[i]);
66 tm_delete (dou[i]);
67 }
68 });
69 bench.batch (NUM).run ("char, bulk collect", [&] {
70 for (int i= 0; i < NUM; i++) {
71 ch[i]= tm_new<char> ();
72 }
73
74 for (int i= 0; i < NUM; i++) {
75 tm_delete (ch[i]);
76 }
77 });
78 bench.run ("int, bulk collect", [&] {
79 for (int i= 0; i < NUM; i++) {
80 in[i]= tm_new<int> ();
81 }
82
83 for (int i= 0; i < NUM; i++) {
84 tm_delete (in[i]);
85 }
86 });
87 bench.run ("long, bulk collect", [&] {
88 for (int i= 0; i < NUM; i++) {
89 lo[i]= tm_new<long> ();
90 }
91
92 for (int i= 0; i < NUM; i++) {
93 tm_delete (lo[i]);
94 }
95 });
96 bench.run ("double, bulk collect", [&] {
97 for (int i= 0; i < NUM; i++) {
98 dou[i]= tm_new<double> ();
99 }
100
101 for (int i= 0; i < NUM; i++) {
102 tm_delete (dou[i]);
103 }
104 });
105 bench.batch (1).run ("struct", [&] {
106 Complex* p_complex= tm_new<Complex> (35.8, 26.2);
108 });
111#ifdef OS_WASM
112 const size_t size_prim= 200, size_complex= 100;
113#else
114 const size_t size_prim= 20000000, size_complex= 5000000;
115#endif
116 bench.batch (size_prim).run ("large array of basic type", [&] {
119 });
120 bench.batch (size_complex).run ("large array of complex structure", [&] {
123 });
124
126 bench.batch (NUM).run ("frequent allocation of array, space reused", [&] {
127 for (int i= 0; i < NUM; i++) {
129 }
130 for (int i= 0; i < NUM; i++) {
132 }
133 });
134 return 0;
135}
The list class represents a linked list.
Definition list.hpp:48
void tm_delete(C *ptr)
void tm_delete_array(C *Ptr)
static ankerl::nanobench::Bench bench
#define NUM
void init_tbox()

Variable Documentation

◆ bench

Definition at line 11 of file fast_alloc_bench.cpp.