30 #include <unordered_set>
32 #define CATCH_CONFIG_RUNNER
34 #include <catch2/catch_amalgamated.hpp>
50 static uint8_t
start_addr_b[] = {0x20, 0x26, 0x2A, 0x01, 0x20, 0x10};
54 #define USE_JAU_ITER_ALGO 1
58 auto search = data.find(elem);
59 if( search != data.end() ) {
69 some_number += e.
nop();
71 REQUIRE(some_number > 0);
75 template<
class T,
typename Size_type>
78 const Size_type size = data.size();
79 Size_type fi = 0, i=0;
81 for(; i<size && a0.
next(); ++i) {
83 const DataType01 *found = jau::find_const<T>(data, elem);
84 if(
nullptr != found ) {
95 const std::size_t size = data.size();
96 std::size_t fi = 0, i=0;
98 for(; i<size && a0.
next(); ++i) {
101 if(
nullptr != found ) {
109 template<
class T,
typename Size_type>
114 for(; i<size && a0.
next(); ++i) {
115 data.emplace_back( a0,
static_cast<uint8_t
>(1) );
117 REQUIRE(i == data.size());
120 template<
class T,
typename Size_type>
125 for(; i<size && a0.
next(); ++i) {
127 const DataType01* exist = jau::find_const<T>(data, elem);
128 if(
nullptr == exist ) {
129 data.push_back( std::move( elem ) );
133 REQUIRE(i == data.size());
140 std::size_t i=0, fi=0;
142 for(; i<size && a0.
next(); ++i) {
143 if( data.emplace(a0,
static_cast<uint8_t
>(1)).second ) {
147 REQUIRE(i == data.size());
152 static void print_mem(
const std::string& pre,
const T& data) {
153 std::size_t bytes_element =
sizeof(
DataType01);
154 std::size_t elements = data.size();
155 std::size_t bytes_net = elements * bytes_element;
156 std::size_t bytes_total = data.get_allocator().memory_usage;
157 double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (
double)bytes_net );
158 printf(
"Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
160 bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
170 template<
class T,
typename Size_type>
171 static bool test_01_seq_fill_list_itr(
const std::string& type_id,
const Size_type size0,
const Size_type reserve0,
const bool do_print_mem) {
173 REQUIRE(0 == data.get_allocator().memory_usage);
174 REQUIRE(data.size() == 0);
178 data.reserve(reserve0);
179 REQUIRE(data.size() == 0);
180 REQUIRE(0 != data.get_allocator().memory_usage);
181 REQUIRE(data.capacity() == reserve0);
184 test_00_seq_fill<T, Size_type>(data, size0);
185 REQUIRE(0 != data.get_allocator().memory_usage);
186 REQUIRE(data.size() == size0);
188 test_00_list_itr<T>(data);
189 REQUIRE(0 != data.get_allocator().memory_usage);
190 REQUIRE(data.size() == size0);
191 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
194 REQUIRE(data.size() == 0);
197 return data.size() == 0;
202 const std::size_t bucket_count = data.bucket_count();
203 std::size_t capacity = 0;
204 for(std::size_t i=0; i<bucket_count; i++) {
205 capacity = data.bucket_size(i);
210 static bool test_01_seq_fill_list_hash(
const std::string& type_id,
const std::size_t size0,
const std::size_t reserve0,
const bool do_print_mem) {
213 REQUIRE(0 == data.get_allocator().memory_usage);
214 REQUIRE(data.size() == 0);
218 data.reserve(reserve0);
219 REQUIRE(data.size() == 0);
220 REQUIRE(0 != data.get_allocator().memory_usage);
221 REQUIRE(get_capacity<DataType01Set>(data) >= reserve0);
225 REQUIRE(0 != data.get_allocator().memory_usage);
226 REQUIRE(data.size() == size0);
228 test_00_list_itr<DataType01Set>(data);
229 REQUIRE(0 != data.get_allocator().memory_usage);
230 REQUIRE(data.size() == size0);
231 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
234 REQUIRE(data.size() == 0);
237 return data.size() == 0;
240 template<
class T,
typename Size_type>
244 REQUIRE(data.size() == 0);
247 data.reserve(reserve0);
248 REQUIRE(data.size() == 0);
249 REQUIRE(data.capacity() == reserve0);
252 test_00_seq_fill_unique_itr<T, Size_type>(data, size0);
253 REQUIRE(data.size() == size0);
255 test_00_seq_find_itr<T, Size_type>(data);
256 REQUIRE(data.size() == size0);
259 REQUIRE(data.size() == 0);
260 return data.size() == 0;
265 typedef std::unordered_set<DataType01, std::hash<DataType01>, std::equal_to<DataType01>, std::allocator<DataType01>> DataType01Set;
267 REQUIRE(data.size() == 0);
270 data.reserve(reserve0);
271 REQUIRE(data.size() == 0);
277 REQUIRE(data.size() == size0);
280 REQUIRE(data.size() == size0);
283 REQUIRE(data.size() == 0);
284 return data.size() == 0;
290 template<
class T,
typename Size_type>
293 test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0,
true);
295 test_01_seq_fill_list_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0,
true);
296 test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0,
true);
311 template<
class T,
typename Size_type>
313 const bool do_rserv) {
315 BENCHMARK(title_pre+
" FillUni_List 1000") {
316 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
322 test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
328 BENCHMARK(title_pre+
" FillUni_List 50") {
329 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
331 BENCHMARK(title_pre+
" FillUni_List 100") {
332 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
334 BENCHMARK(title_pre+
" FillUni_List 1000") {
335 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
341 const bool do_rserv) {
343 BENCHMARK(title_pre+
" FillUni_List 1000") {
356 BENCHMARK(title_pre+
" FillUni_List 50") {
359 BENCHMARK(title_pre+
" FillUni_List 100") {
362 BENCHMARK(title_pre+
" FillUni_List 1000") {
370 TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
373 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_empty_",
false);
374 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"cowdarray_empty_",
false);
378 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"stdvec_empty_",
false);
379 footprint_fillseq_list_itr< jau::darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"darray_empty_",
false);
380 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_empty_",
false);
381 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"cowdarray_empty_",
false);
384 TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
387 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_empty_itr",
"cowstdvec_empty_",
false);
388 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_empty_itr",
"cowdarray_empty_",
false);
393 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_empty_itr",
"stdvec_empty_",
false);
394 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_empty_itr",
"darray_empty_",
false);
395 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_empty_itr",
"cowstdvec_empty_",
false);
396 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_empty_itr",
"cowdarray_empty_",
false);
399 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_rserv_itr",
"stdvec_rserv",
true);
400 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_rserv_itr",
"darray_rserv",
true);
401 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_rserv_itr",
"cowstdvec_rserv",
true);
402 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_rserv_itr",
"cowdarray_rserv",
true);