31 #define CATCH_CONFIG_RUNNER
33 #include <catch2/catch_amalgamated.hpp>
52 #define RUN_RESERVE_BENCHMARK 0
53 #define RUN_INDEXED_BENCHMARK 0
58 template<
class Cont >
62 printf(
"\nContainer Type %s (a darray, a cow %d):\n - Uses memcpy %d (trivially_copyable %d); realloc %d; base_of jau::callocator %d; size %d bytes\n",
65 std::is_trivially_copyable<typename Cont::value_type>::value,
75 printf(
"\nContainer Type %s (!darray, a cow %d); size %d bytes\n",
82 static uint8_t
start_addr_b[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
88 template<
class T,
typename Size_type>
90 const Size_type size = data.size();
91 for (Size_type i = 0; i < size; ++i) {
100 template<
class T,
typename Size_type>
103 const Size_type size = data.size();
104 for (Size_type i = 0; i < size; ++i) {
106 some_number += e.
nop();
108 REQUIRE(some_number > 0);
112 template<
class T,
typename Size_type>
116 typename T::const_iterator first = data.cbegin();
117 for (; !first.is_end(); ++first) {
118 if (*first == elem) {
124 template<
class T,
typename Size_type>
128 typename T::const_iterator first = data.cbegin();
129 typename T::const_iterator last = data.cend();
130 for (; first != last; ++first) {
131 if (*first == elem) {
143 typename T::const_iterator first = data.cbegin();
144 for (; !first.is_end(); ++first) {
145 some_number += (*first).nop();
147 REQUIRE(some_number > 0);
156 typename T::const_iterator first = data.cbegin();
157 typename T::const_iterator last = data.cend();
158 for (; first != last; ++first) {
159 some_number += (*first).nop();
161 REQUIRE(some_number > 0);
166 template<
class T,
typename Size_type>
169 const Size_type size = data.size();
170 Size_type fi = 0, i=0;
172 for(; i<size && a0.
next(); ++i) {
174 const DataType01 *found = findDataSet01_idx<T, Size_type>(data, elem);
175 if(
nullptr != found ) {
183 template<
class T,
typename Size_type>
186 const Size_type size = data.size();
187 Size_type fi = 0, i=0;
189 for(; i<size && a0.
next(); ++i) {
191 const DataType01 *found = findDataSet01_itr<T, Size_type>(data, elem);
192 if(
nullptr != found ) {
200 template<
class T,
typename Size_type>
205 for(; i<size && a0.
next(); ++i) {
206 data.emplace_back( a0,
static_cast<uint8_t
>(1) );
208 REQUIRE(i == data.size());
211 template<
class T,
typename Size_type>
216 for(; i<size && a0.
next(); ++i) {
218 const DataType01* exist = findDataSet01_idx<T, Size_type>(data, elem);
219 if(
nullptr == exist ) {
220 data.push_back( std::move( elem ) );
224 REQUIRE(i == data.size());
228 template<
class value_type>
233 template<
class T,
typename Size_type>
241 typename T::iterator first = data.begin();
243 for(; i<size && a0.
next(); ++i, first.to_begin()) {
245 for (; !first.is_end(); ++first) {
246 if (*first == elem) {
250 if( first.is_end() ) {
251 first.push_back( std::move( elem ) );
257 for(; i<size && a0.
next(); ++i) {
258 if( data.push_back_unique(
DataType01(a0,
static_cast<uint8_t
>(1)),
259 equal_comparator<typename T::value_type> ) ) {
264 REQUIRE(i == data.size());
268 template<
class T,
typename Size_type>
275 for(; i<size && a0.
next(); ++i) {
277 typename T::const_iterator first = data.cbegin();
278 typename T::const_iterator last = data.cend();
279 for (; first != last; ++first) {
280 if (*first == elem) {
284 if( first == last ) {
285 data.push_back( std::move( elem ) );
289 REQUIRE(i == data.size());
294 static void print_mem(
const std::string& pre,
const T& data) {
295 std::size_t bytes_element =
sizeof(
DataType01);
296 std::size_t elements = data.size();
297 std::size_t bytes_net = elements * bytes_element;
298 std::size_t bytes_total = data.get_allocator().memory_usage;
299 double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (
double)bytes_net );
300 printf(
"Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
302 bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
311 template<
class T,
typename Size_type>
315 REQUIRE(data.size() == 0);
318 data.reserve(reserve0);
319 REQUIRE(data.size() == 0);
320 REQUIRE(data.capacity() == reserve0);
323 test_00_seq_fill<T, Size_type>(data, size0);
324 REQUIRE(data.size() == size0);
325 REQUIRE(data.capacity() >= size0);
327 test_00_list_idx<T, Size_type>(data);
328 REQUIRE(data.size() == size0);
329 REQUIRE(data.capacity() >= size0);
332 REQUIRE(data.size() == 0);
333 return data.size() == 0;
336 template<
class T,
typename Size_type>
339 REQUIRE(0 == data.get_allocator().memory_usage);
340 REQUIRE(data.size() == 0);
344 data.reserve(reserve0);
345 REQUIRE(data.size() == 0);
346 REQUIRE(0 != data.get_allocator().memory_usage);
347 REQUIRE(data.capacity() == reserve0);
350 test_00_seq_fill<T, Size_type>(data, size0);
351 REQUIRE(0 != data.get_allocator().memory_usage);
352 REQUIRE(data.size() == size0);
353 REQUIRE(data.capacity() >= size0);
355 test_00_list_itr<T>(data);
356 REQUIRE(0 != data.get_allocator().memory_usage);
357 REQUIRE(data.size() == size0);
358 REQUIRE(data.capacity() >= size0);
359 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
362 REQUIRE(data.size() == 0);
365 return data.size() == 0;
368 template<
class T,
typename Size_type>
372 REQUIRE(data.size() == 0);
375 data.reserve(reserve0);
376 REQUIRE(data.size() == 0);
377 REQUIRE(data.capacity() == reserve0);
380 test_00_seq_fill<T, Size_type>(data, size0);
381 REQUIRE(data.size() == size0);
382 REQUIRE(data.capacity() >= size0);
384 test_00_list_itr<T>(data);
385 REQUIRE(data.size() == size0);
386 REQUIRE(data.capacity() >= size0);
389 REQUIRE(data.size() == 0);
390 return data.size() == 0;
393 template<
class T,
typename Size_type>
397 REQUIRE(data.size() == 0);
400 data.reserve(reserve0);
401 REQUIRE(data.size() == 0);
402 REQUIRE(data.capacity() == reserve0);
405 test_00_seq_fill_unique_idx<T, Size_type>(data, size0);
406 REQUIRE(data.size() == size0);
407 REQUIRE(data.capacity() >= size0);
409 test_00_seq_find_idx<T, Size_type>(data);
410 REQUIRE(data.size() == size0);
411 REQUIRE(data.capacity() >= size0);
414 REQUIRE(data.size() == 0);
415 return data.size() == 0;
417 template<
class T,
typename Size_type>
421 REQUIRE(data.size() == 0);
424 data.reserve(reserve0);
425 REQUIRE(data.size() == 0);
426 REQUIRE(data.capacity() == reserve0);
429 test_00_seq_fill_unique_itr<T, Size_type>(data, size0);
430 REQUIRE(data.size() == size0);
431 REQUIRE(data.capacity() >= size0);
433 test_00_seq_find_itr<T, Size_type>(data);
434 REQUIRE(data.size() == size0);
435 REQUIRE(data.capacity() >= size0);
438 REQUIRE(data.size() == 0);
439 return data.size() == 0;
445 template<
class T,
typename Size_type>
452 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 50, do_rserv? 50 : 0,
true);
454 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 100, do_rserv? 100 : 0,
true);
455 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0,
true);
460 template<
class T,
typename Size_type>
462 const bool do_rserv) {
463 #if RUN_INDEXED_BENCHMARK
469 BENCHMARK(title_pre+
" FillSeq_List 1000") {
470 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
475 test_01_seq_fill_list_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
481 BENCHMARK(title_pre+
" FillSeq_List 50") {
482 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
484 BENCHMARK(title_pre+
" FillSeq_List 100") {
485 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
487 BENCHMARK(title_pre+
" FillSeq_List 1000") {
488 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
497 template<
class T,
typename Size_type>
499 const bool do_rserv) {
505 BENCHMARK(title_pre+
" FillSeq_List 1000") {
506 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
512 test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
518 BENCHMARK(title_pre+
" FillSeq_List 50") {
519 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
521 BENCHMARK(title_pre+
" FillSeq_List 100") {
522 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
524 BENCHMARK(title_pre+
" FillSeq_List 1000") {
525 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
530 template<
class T,
typename Size_type>
532 const bool do_rserv) {
533 #if RUN_INDEXED_BENCHMARK
539 BENCHMARK(title_pre+
" FillUni_List 1000") {
540 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
545 test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
551 BENCHMARK(title_pre+
" FillUni_List 50") {
552 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
554 BENCHMARK(title_pre+
" FillUni_List 100") {
555 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
557 BENCHMARK(title_pre+
" FillUni_List 1000") {
558 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
567 template<
class T,
typename Size_type>
569 const bool do_rserv) {
575 BENCHMARK(title_pre+
" FillUni_List 1000") {
576 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
582 test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
588 BENCHMARK(title_pre+
" FillUni_List 50") {
589 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
591 BENCHMARK(title_pre+
" FillUni_List 100") {
592 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
594 BENCHMARK(title_pre+
" FillUni_List 1000") {
595 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
603 TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
609 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"stdvec_def_empty_",
false);
610 footprint_fillseq_list_itr< jau::darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"darray_def_empty_",
false);
611 footprint_fillseq_list_itr< jau::darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"darray_mmm_empty_",
false);
612 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_def_empty_",
false);
613 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"cowdarray_def_empty_",
false);
614 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"cowdarray_mmm_empty_",
false);
616 #if RUN_RESERVE_BENCHMARK
617 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"stdvec_def_rserv",
true);
618 footprint_fillseq_list_itr< jau::darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"darray_def_rserv",
true);
619 footprint_fillseq_list_itr< jau::darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"darray_mmm_rserv",
true);
620 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_def_rserv",
true);
621 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"cowdarray_def_rserv",
true);
622 footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"cowdarray_mmm_rserv",
true);
626 TEST_CASE(
"Perf Test 01 - Fill Sequential and List, empty and reserve",
"[datatype][sequential]" ) {
630 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_empty_itr",
"stdvec_empty_",
false);
631 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_empty_itr",
"darray_empty_",
false);
632 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_empty_itr",
"darray_empty_",
false);
633 #if RUN_RESERVE_BENCHMARK
634 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_rserv_itr",
"stdvec_rserv",
true);
635 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_rserv_itr",
"darray_rserv",
true);
636 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_rserv_itr",
"darray_rserv",
true);
640 benchmark_fillseq_list_idx< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_empty_idx",
"stdvec_empty_",
false);
641 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_empty_itr",
"stdvec_empty_",
false);
643 benchmark_fillseq_list_idx< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_empty_idx",
"darray_empty_",
false);
644 benchmark_fillseq_list_idx< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_empty_idx",
"darray_empty_",
false);
645 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_empty_itr",
"darray_empty_",
false);
646 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_empty_itr",
"darray_empty_",
false);
648 benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_empty_itr",
"cowstdvec_empty_",
false);
650 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_def_empty_itr",
"cowdarray_empty_",
false);
651 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"COW_DArray_mmm_empty_itr",
"cowdarray_empty_",
false);
653 #if RUN_RESERVE_BENCHMARK
654 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_rserv_itr",
"stdvec_rserv",
true);
655 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_rserv_itr",
"darray_rserv",
true);
656 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_rserv_itr",
"darray_rserv",
true);
657 benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_rserv_itr",
"cowstdvec_rserv",
true);
658 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>, std::size_t>(
"COW_DArray_def_rserv_itr",
"cowdarray_rserv",
true);
659 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>, std::size_t>(
"COW_DArray_mmm_rserv_itr",
"cowdarray_rserv",
true);
663 TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
665 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_empty_itr",
"cowstdvec_empty_",
false);
666 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_def_empty_itr",
"cowdarray_empty_",
false);
667 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"COW_DArray_mmm_empty_itr",
"cowdarray_empty_",
false);
668 #if RUN_RESERVE_BENCHMARK
669 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_rserv_itr",
"cowstdvec_rserv",
true);
670 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_def_rserv_itr",
"cowdarray_rserv",
true);
671 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"COW_DArray_mmm_rserv_itr",
"cowdarray_rserv",
true);
675 benchmark_fillunique_find_idx< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_empty_idx",
"stdvec_empty_",
false);
676 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_empty_itr",
"stdvec_empty_",
false);
678 benchmark_fillunique_find_idx< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_empty_idx",
"darray_empty_",
false);
679 benchmark_fillunique_find_idx< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_empty_idx",
"darray_empty_",
false);
680 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_empty_itr",
"darray_empty_",
false);
681 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_empty_itr",
"darray_empty_",
false);
683 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_empty_itr",
"cowstdvec_empty_",
false);
685 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_def_empty_itr",
"cowdarray_empty_",
false);
686 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"COW_DArray_mmm_empty_itr",
"cowdarray_empty_",
false);
688 #if RUN_RESERVE_BENCHMARK
689 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_def_rserv_itr",
"stdvec_rserv",
true);
690 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"JAU_DArray_def_rserv_itr",
"darray_rserv",
true);
691 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"JAU_DArray_mmm_rserv_itr",
"darray_rserv",
true);
692 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_def_rserv_itr",
"cowstdvec_rserv",
true);
693 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t>,
jau::nsize_t>(
"COW_DArray_def_rserv_itr",
"cowdarray_rserv",
true);
694 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::callocator<DataType01>,
jau::nsize_t,
true,
true>,
jau::nsize_t>(
"COW_DArray_mmm_rserv_itr",
"cowdarray_rserv",
true);