jaulib v1.3.0
Jau Support Library (C++, Java, ..)
test_cow_darray_perf01.cpp
Go to the documentation of this file.
1/*
2 * Author: Sven Gothel <sgothel@jausoft.com>
3 * Copyright (c) 2020 Gothel Software e.K.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24#include <cassert>
25#include <cinttypes>
26#include <cstring>
27#include <random>
28#include <vector>
29
31
32#include "test_datatype01.hpp"
33
34#include <jau/basic_types.hpp>
35#include <jau/basic_algos.hpp>
36#include <jau/darray.hpp>
37#include <jau/cow_darray.hpp>
38#include <jau/cow_vector.hpp>
40#include <jau/callocator.hpp>
42
43/**
44 * Performance test of jau::darray, jau::cow_darray and jau::cow_vector.
45 */
46using namespace jau;
47
48#define RUN_RESERVE_BENCHMARK 0
49#define RUN_INDEXED_BENCHMARK 0
50
51/****************************************************************************************
52 ****************************************************************************************/
53
54template< class Cont >
55static void print_container_info(const std::string& type_id, const Cont &c,
56 std::enable_if_t< jau::is_darray_type<Cont>::value, bool> = true )
57{
58 printf("\nContainer Type %s (a darray, a cow %d):\n - Uses memmove %d (trivially_copyable %d); realloc %d; base_of jau::callocator %d; secmem %d; size %d bytes\n",
59 type_id.c_str(), jau::is_cow_type<Cont>::value,
60 Cont::uses_memmove,
61 std::is_trivially_copyable<typename Cont::value_type>::value,
62 Cont::uses_realloc,
63 std::is_base_of<jau::callocator<typename Cont::value_type>, typename Cont::allocator_type>::value,
64 Cont::uses_secmem,
65 (int)sizeof(c));
66}
67
68template<class Cont>
69static void print_container_info(const std::string& type_id, const Cont &c,
70 std::enable_if_t< !jau::is_darray_type<Cont>::value, bool> = true )
71{
72 printf("\nContainer Type %s (!darray, a cow %d); size %d bytes\n",
73 type_id.c_str(), jau::is_cow_type<Cont>::value, (int)sizeof(c));
74}
75
76/****************************************************************************************
77 ****************************************************************************************/
78
79static uint8_t start_addr_b[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
81
82/****************************************************************************************
83 ****************************************************************************************/
84
85template<class T, typename Size_type>
86const DataType01 * findDataSet01_idx(T& data, DataType01 const & elem) noexcept {
87 const Size_type size = data.size();
88 for (Size_type i = 0; i < size; ++i) {
89 DataType01 & e = data[i];
90 if ( elem == e ) {
91 return &e;
92 }
93 }
94 return nullptr;
95}
96
97template<class T, typename Size_type>
98static int test_00_list_idx(T& data) {
99 int some_number = 0; // add some validated work, avoiding any 'optimization away'
100 const Size_type size = data.size();
101 for (Size_type i = 0; i < size; ++i) {
102 const DataType01 & e = data[i];
103 some_number += e.nop();
104 }
105 REQUIRE(some_number > 0);
106 return some_number;
107}
108
109template<class T, typename Size_type>
110const DataType01 * findDataSet01_itr(T& data, DataType01 const & elem,
111 std::enable_if_t< is_cow_type<T>::value, bool> = true) noexcept
112{
113 typename T::const_iterator first = data.cbegin();
114 for (; !first.is_end(); ++first) {
115 if (*first == elem) {
116 return &(*first);
117 }
118 }
119 return nullptr;
120}
121template<class T, typename Size_type>
122const DataType01 * findDataSet01_itr(T& data, DataType01 const & elem,
123 std::enable_if_t< !is_cow_type<T>::value, bool> = true) noexcept
124{
125 typename T::const_iterator first = data.cbegin();
126 typename T::const_iterator last = data.cend();
127 for (; first != last; ++first) {
128 if (*first == elem) {
129 return &(*first);
130 }
131 }
132 return nullptr;
133}
134
135template<class T>
136static int test_00_list_itr(T& data,
137 std::enable_if_t< is_cow_type<T>::value, bool> = true )
138{
139 int some_number = 0; // add some validated work, avoiding any 'optimization away'
140 typename T::const_iterator first = data.cbegin();
141 for (; !first.is_end(); ++first) {
142 some_number += (*first).nop();
143 }
144 REQUIRE(some_number > 0);
145 return some_number;
146}
147
148template<class T>
149static int test_00_list_itr(T& data,
150 std::enable_if_t< !is_cow_type<T>::value, bool> = true )
151{
152 int some_number = 0; // add some validated work, avoiding any 'optimization away'
153 typename T::const_iterator first = data.cbegin();
154 typename T::const_iterator last = data.cend();
155 for (; first != last; ++first) {
156 some_number += (*first).nop();
157 }
158 REQUIRE(some_number > 0);
159 return some_number;
160}
161
162
163template<class T, typename Size_type>
164static void test_00_seq_find_idx(T& data) {
166 const Size_type size = data.size();
167 Size_type fi = 0, i=0;
168
169 for(; i<size && a0.next(); ++i) {
170 DataType01 elem(a0, static_cast<uint8_t>(1));
171 const DataType01 *found = findDataSet01_idx<T, Size_type>(data, elem);
172 if( nullptr != found ) {
173 ++fi;
174 found->nop();
175 }
176 }
177 REQUIRE(fi == i);
178}
179
180template<class T, typename Size_type>
181static void test_00_seq_find_itr(T& data) {
183 const Size_type size = data.size();
184 Size_type fi = 0, i=0;
185
186 for(; i<size && a0.next(); ++i) {
187 DataType01 elem(a0, static_cast<uint8_t>(1));
188 const DataType01 *found = findDataSet01_itr<T, Size_type>(data, elem);
189 if( nullptr != found ) {
190 ++fi;
191 found->nop();
192 }
193 }
194 REQUIRE(fi == i);
195}
196
197template<class T, typename Size_type>
198static void test_00_seq_fill(T& data, const Size_type size) {
200 Size_type i=0;
201
202 for(; i<size && a0.next(); ++i) {
203 data.emplace_back( a0, static_cast<uint8_t>(1) );
204 }
205 REQUIRE(i == data.size());
206}
207
208template<class T, typename Size_type>
209static void test_00_seq_fill_unique_idx(T& data, const Size_type size) {
211 Size_type i=0, fi=0;
212
213 for(; i<size && a0.next(); ++i) {
214 DataType01 elem(a0, static_cast<uint8_t>(1));
215 const DataType01* exist = findDataSet01_idx<T, Size_type>(data, elem);
216 if( nullptr == exist ) {
217 data.push_back( std::move( elem ) );
218 ++fi;
219 }
220 }
221 REQUIRE(i == data.size());
222 REQUIRE(fi == size);
223}
224
225template<class value_type>
226static bool equal_comparator(const value_type& a, const value_type& b) {
227 return a == b;
228}
229
230template<class T, typename Size_type>
231static void test_00_seq_fill_unique_itr(T& data, const Size_type size,
232 std::enable_if_t< is_cow_type<T>::value, bool> = true)
233{
235 Size_type i=0, fi=0;
236
237#if 0
238 typename T::iterator first = data.begin();
239
240 for(; i<size && a0.next(); ++i, first.to_begin()) {
241 DataType01 elem(a0, static_cast<uint8_t>(1));
242 for (; !first.is_end(); ++first) {
243 if (*first == elem) {
244 break;
245 }
246 }
247 if( first.is_end() ) {
248 first.push_back( std::move( elem ) );
249 ++fi;
250 }
251 }
252 first.write_back();
253#else
254 for(; i<size && a0.next(); ++i) {
255 if( data.push_back_unique( DataType01(a0, static_cast<uint8_t>(1)),
256 equal_comparator<typename T::value_type> ) ) {
257 ++fi;
258 }
259 }
260#endif
261 REQUIRE(i == data.size());
262 REQUIRE(fi == size);
263}
264
265template<class T, typename Size_type>
266static void test_00_seq_fill_unique_itr(T& data, const Size_type size,
267 std::enable_if_t< !is_cow_type<T>::value, bool> = true)
268{
270 Size_type i=0, fi=0;
271
272 for(; i<size && a0.next(); ++i) {
273 DataType01 elem(a0, static_cast<uint8_t>(1));
274 typename T::const_iterator first = data.cbegin();
275 typename T::const_iterator last = data.cend();
276 for (; first != last; ++first) {
277 if (*first == elem) {
278 break;
279 }
280 }
281 if( first == last ) {
282 data.push_back( std::move( elem ) );
283 ++fi;
284 }
285 }
286 REQUIRE(i == data.size());
287 REQUIRE(fi == size);
288}
289
290template<class T>
291static void print_mem(const std::string& pre, const T& data) {
292 std::size_t bytes_element = sizeof(DataType01);
293 std::size_t elements = data.size();
294 std::size_t bytes_net = elements * bytes_element;
295 std::size_t bytes_total = data.get_allocator().memory_usage;
296 double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (double)bytes_net );
297 printf("Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
298 pre.c_str(), to_decstring(elements, ',', 5).c_str(),
299 bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
300 // 5: 1,000
301 // 7: 100,000
302 // 9: 1,000,000
303}
304
305/****************************************************************************************
306 ****************************************************************************************/
307
308template<class T, typename Size_type>
309static bool test_01_seq_fill_list_idx(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
310 (void)type_id;
311 T data;
312 REQUIRE(data.size() == 0);
313
314 if( 0 < reserve0 ) {
315 data.reserve(reserve0);
316 REQUIRE(data.size() == 0);
317 REQUIRE(data.capacity() == reserve0);
318 }
319
320 test_00_seq_fill<T, Size_type>(data, size0);
321 REQUIRE(data.size() == size0);
322 REQUIRE(data.capacity() >= size0);
323
324 test_00_list_idx<T, Size_type>(data);
325 REQUIRE(data.size() == size0);
326 REQUIRE(data.capacity() >= size0);
327
328 data.clear();
329 REQUIRE(data.size() == 0);
330 return data.size() == 0;
331}
332
333template<class T, typename Size_type>
334static bool test_01_seq_fill_list_footprint(const std::string& type_id, const Size_type size0, const Size_type reserve0, const bool do_print_mem) {
335 T data;
336 REQUIRE(0 == data.get_allocator().memory_usage);
337 REQUIRE(data.size() == 0);
338 // if( do_print_mem ) { print_mem(type_id+" 01 (empty)", data); }
339
340 if( 0 < reserve0 ) {
341 data.reserve(reserve0);
342 REQUIRE(data.size() == 0);
343 REQUIRE(0 != data.get_allocator().memory_usage);
344 REQUIRE(data.capacity() == reserve0);
345 }
346
347 test_00_seq_fill<T, Size_type>(data, size0);
348 REQUIRE(0 != data.get_allocator().memory_usage);
349 REQUIRE(data.size() == size0);
350 REQUIRE(data.capacity() >= size0);
351
352 test_00_list_itr<T>(data);
353 REQUIRE(0 != data.get_allocator().memory_usage);
354 REQUIRE(data.size() == size0);
355 REQUIRE(data.capacity() >= size0);
356 if( do_print_mem ) { print_mem(type_id+" 01 (full_)", data); }
357
358 data.clear();
359 REQUIRE(data.size() == 0);
360 // if( do_print_mem ) { print_mem(type_id+" 01 (clear)", data); }
361 // REQUIRE(0 == data.get_allocator().memory_usage);
362 return data.size() == 0;
363}
364
365template<class T, typename Size_type>
366static bool test_01_seq_fill_list_itr(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
367 (void)type_id;
368 T data;
369 REQUIRE(data.size() == 0);
370
371 if( 0 < reserve0 ) {
372 data.reserve(reserve0);
373 REQUIRE(data.size() == 0);
374 REQUIRE(data.capacity() == reserve0);
375 }
376
377 test_00_seq_fill<T, Size_type>(data, size0);
378 REQUIRE(data.size() == size0);
379 REQUIRE(data.capacity() >= size0);
380
381 test_00_list_itr<T>(data);
382 REQUIRE(data.size() == size0);
383 REQUIRE(data.capacity() >= size0);
384
385 data.clear();
386 REQUIRE(data.size() == 0);
387 return data.size() == 0;
388}
389
390template<class T, typename Size_type>
391static bool test_02_seq_fillunique_find_idx(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
392 (void)type_id;
393 T data;
394 REQUIRE(data.size() == 0);
395
396 if( 0 < reserve0 ) {
397 data.reserve(reserve0);
398 REQUIRE(data.size() == 0);
399 REQUIRE(data.capacity() == reserve0);
400 }
401
402 test_00_seq_fill_unique_idx<T, Size_type>(data, size0);
403 REQUIRE(data.size() == size0);
404 REQUIRE(data.capacity() >= size0);
405
406 test_00_seq_find_idx<T, Size_type>(data);
407 REQUIRE(data.size() == size0);
408 REQUIRE(data.capacity() >= size0);
409
410 data.clear();
411 REQUIRE(data.size() == 0);
412 return data.size() == 0;
413}
414template<class T, typename Size_type>
415static bool test_02_seq_fillunique_find_itr(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
416 (void)type_id;
417 T data;
418 REQUIRE(data.size() == 0);
419
420 if( 0 < reserve0 ) {
421 data.reserve(reserve0);
422 REQUIRE(data.size() == 0);
423 REQUIRE(data.capacity() == reserve0);
424 }
425
426 test_00_seq_fill_unique_itr<T, Size_type>(data, size0);
427 REQUIRE(data.size() == size0);
428 REQUIRE(data.capacity() >= size0);
429
430 test_00_seq_find_itr<T, Size_type>(data);
431 REQUIRE(data.size() == size0);
432 REQUIRE(data.capacity() >= size0);
433
434 data.clear();
435 REQUIRE(data.size() == 0);
436 return data.size() == 0;
437}
438
439/****************************************************************************************
440 ****************************************************************************************/
441
442template<class T, typename Size_type>
443static bool footprint_fillseq_list_itr(const std::string& type_id, const bool do_rserv) {
444 {
445 T data;
446 print_container_info(type_id, data);
447 }
448 // test_01_seq_fill_list_footprint<T, Size_type>(type_id, 25, do_rserv? 25 : 0, true);
449 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 50, do_rserv? 50 : 0, true);
450 if( !catch_auto_run ) {
451 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 100, do_rserv? 100 : 0, true);
452 test_01_seq_fill_list_footprint<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0, true);
453 }
454 return true;
455}
456
457template<class T, typename Size_type>
458static bool benchmark_fillseq_list_idx(const std::string& title_pre, const std::string& type_id,
459 const bool do_rserv) {
460#if RUN_INDEXED_BENCHMARK
461 {
462 T data;
463 print_container_info(title_pre, data);
464 }
465 if( catch_perf_analysis ) {
466 BENCHMARK(title_pre+" FillSeq_List 1000") {
467 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
468 };
469 return true;
470 }
471 if( catch_auto_run ) {
472 test_01_seq_fill_list_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
473 return true;
474 }
475 // BENCHMARK(title_pre+" FillSeq_List 25") {
476 // return test_01_seq_fill_list_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
477 // };
478 BENCHMARK(title_pre+" FillSeq_List 50") {
479 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
480 };
481 BENCHMARK(title_pre+" FillSeq_List 100") {
482 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
483 };
484 BENCHMARK(title_pre+" FillSeq_List 1000") {
485 return test_01_seq_fill_list_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
486 };
487#else
488 (void) title_pre;
489 (void) type_id;
490 (void) do_rserv;
491#endif
492 return true;
493}
494template<class T, typename Size_type>
495static bool benchmark_fillseq_list_itr(const std::string& title_pre, const std::string& type_id,
496 const bool do_rserv) {
497 {
498 T data;
499 print_container_info(title_pre, data);
500 }
501 if( catch_perf_analysis ) {
502 BENCHMARK(title_pre+" FillSeq_List 1000") {
503 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
504 };
505 // test_01_seq_fill_list_itr<T, Size_type>(type_id, 100000, do_rserv? 100000 : 0);
506 return true;
507 }
508 if( catch_auto_run ) {
509 test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
510 return true;
511 }
512 // BENCHMARK(title_pre+" FillSeq_List 25") {
513 // return test_01_seq_fill_list_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
514 // };
515 BENCHMARK(title_pre+" FillSeq_List 50") {
516 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
517 };
518 BENCHMARK(title_pre+" FillSeq_List 100") {
519 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
520 };
521 BENCHMARK(title_pre+" FillSeq_List 1000") {
522 return test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
523 };
524 return true;
525}
526
527template<class T, typename Size_type>
528static bool benchmark_fillunique_find_idx(const std::string& title_pre, const std::string& type_id,
529 const bool do_rserv) {
530#if RUN_INDEXED_BENCHMARK
531 {
532 T data;
533 print_container_info(title_pre, data);
534 }
535 if( catch_perf_analysis ) {
536 BENCHMARK(title_pre+" FillUni_List 1000") {
537 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
538 };
539 return true;
540 }
541 if( catch_auto_run ) {
542 test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
543 return true;
544 }
545 // BENCHMARK(title_pre+" FillUni_List 25") {
546 // return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
547 // };
548 BENCHMARK(title_pre+" FillUni_List 50") {
549 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
550 };
551 BENCHMARK(title_pre+" FillUni_List 100") {
552 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
553 };
554 BENCHMARK(title_pre+" FillUni_List 1000") {
555 return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
556 };
557#else
558 (void) title_pre;
559 (void) type_id;
560 (void) do_rserv;
561#endif
562 return true;
563}
564template<class T, typename Size_type>
565static bool benchmark_fillunique_find_itr(const std::string& title_pre, const std::string& type_id,
566 const bool do_rserv) {
567 {
568 T data;
569 print_container_info(title_pre, data);
570 }
571 if( catch_perf_analysis ) {
572 BENCHMARK(title_pre+" FillUni_List 1000") {
573 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
574 };
575 // test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100000, do_rserv? 100000 : 0);
576 return true;
577 }
578 if( catch_auto_run ) {
579 test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
580 return true;
581 }
582 // BENCHMARK(title_pre+" FillUni_List 25") {
583 // return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
584 // };
585 BENCHMARK(title_pre+" FillUni_List 50") {
586 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
587 };
588 BENCHMARK(title_pre+" FillUni_List 100") {
589 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
590 };
591 BENCHMARK(title_pre+" FillUni_List 1000") {
592 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
593 };
594 return true;
595}
596
597/****************************************************************************************
598 ****************************************************************************************/
599
600TEST_CASE( "Memory Footprint 01 - Fill Sequential and List", "[datatype][footprint]" ) {
601 if( catch_perf_analysis ) {
602 // footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>("cowstdvec_empty_", false);
603 // footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>, jau::nsize_t>, jau::nsize_t>("cowdarray_empty_", false);
604 return;
605 }
606 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>("stdvec_def_empty_", false);
607 footprint_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>, jau::nsize_t>("darray_def_empty_", false);
608 footprint_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, counting_callocator<DataType01>, true /* memmove */>, jau::nsize_t>("darray_mmm_empty_", false);
609 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>("cowstdvec_def_empty_", false);
610 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>, jau::nsize_t>("cowdarray_def_empty_", false);
611 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>, true /* memmove */>, jau::nsize_t>("cowdarray_mmm_empty_", false);
612
613#if RUN_RESERVE_BENCHMARK
614 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>("stdvec_def_rserv", true);
615 footprint_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>, jau::nsize_t>("darray_def_rserv", true);
616 footprint_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, counting_callocator<DataType01>, true /* memmove */>, jau::nsize_t>("darray_mmm_rserv", true);
617 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>("cowstdvec_def_rserv", true);
618 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>, jau::nsize_t>("cowdarray_def_rserv", true);
619 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>, true /* memmove */>, jau::nsize_t>("cowdarray_mmm_rserv", true);
620#endif
621}
622
623TEST_CASE( "Perf Test 01 - Fill Sequential and List, empty and reserve", "[datatype][sequential]" ) {
624 if( catch_perf_analysis ) {
625 // benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
626 // benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_itr", "darray_empty_", false);
627 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_empty_itr", "stdvec_empty_", false);
628 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_itr", "darray_empty_", false);
629 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_empty_itr", "darray_empty_", false);
630#if RUN_RESERVE_BENCHMARK
631 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_rserv_itr", "stdvec_rserv", true);
632 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_rserv_itr", "darray_rserv", true);
633 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_rserv_itr", "darray_rserv", true);
634#endif
635 return;
636 }
637 benchmark_fillseq_list_idx< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_empty_idx", "stdvec_empty_", false);
638 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_empty_itr", "stdvec_empty_", false);
639
640 benchmark_fillseq_list_idx< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_idx", "darray_empty_", false);
641 benchmark_fillseq_list_idx< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_empty_idx", "darray_empty_", false);
642 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_itr", "darray_empty_", false);
643 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_empty_itr", "darray_empty_", false);
644
645 benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
646
647 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("COW_DArray_def_empty_itr", "cowdarray_empty_", false);
648 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("COW_DArray_mmm_empty_itr", "cowdarray_empty_", false);
649
650#if RUN_RESERVE_BENCHMARK
651 benchmark_fillseq_list_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_rserv_itr", "stdvec_rserv", true);
652 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_rserv_itr", "darray_rserv", true);
653 benchmark_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_rserv_itr", "darray_rserv", true);
654 benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_rserv_itr", "cowstdvec_rserv", true);
655 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, std::size_t>("COW_DArray_def_rserv_itr", "cowdarray_rserv", true);
656 benchmark_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, std::size_t>("COW_DArray_mmm_rserv_itr", "cowdarray_rserv", true);
657#endif
658}
659
660TEST_CASE( "Perf Test 02 - Fill Unique and List, empty and reserve", "[datatype][unique]" ) {
661 if( catch_perf_analysis ) {
662 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
663 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("COW_DArray_def_empty_itr", "cowdarray_empty_", false);
664 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("COW_DArray_mmm_empty_itr", "cowdarray_empty_", false);
665#if RUN_RESERVE_BENCHMARK
666 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_rserv_itr", "cowstdvec_rserv", true);
667 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("COW_DArray_def_rserv_itr", "cowdarray_rserv", true);
668 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("COW_DArray_mmm_rserv_itr", "cowdarray_rserv", true);
669#endif
670 return;
671 }
672 benchmark_fillunique_find_idx< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_empty_idx", "stdvec_empty_", false);
673 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_empty_itr", "stdvec_empty_", false);
674
675 benchmark_fillunique_find_idx< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_idx", "darray_empty_", false);
676 benchmark_fillunique_find_idx< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_empty_idx", "darray_empty_", false);
677 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_empty_itr", "darray_empty_", false);
678 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_empty_itr", "darray_empty_", false);
679
680 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
681
682 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("COW_DArray_def_empty_itr", "cowdarray_empty_", false);
683 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("COW_DArray_mmm_empty_itr", "cowdarray_empty_", false);
684
685#if RUN_RESERVE_BENCHMARK
686 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>("STD_Vector_def_rserv_itr", "stdvec_rserv", true);
687 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("JAU_DArray_def_rserv_itr", "darray_rserv", true);
688 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("JAU_DArray_mmm_rserv_itr", "darray_rserv", true);
689 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_rserv_itr", "cowstdvec_rserv", true);
690 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>, jau::nsize_t>("COW_DArray_def_rserv_itr", "cowdarray_rserv", true);
691 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>, true /* memmove */>, jau::nsize_t>("COW_DArray_mmm_rserv_itr", "cowdarray_rserv", true);
692#endif
693}
694
bool catch_perf_analysis
Run w/ command-line arg '–perf_analysis'.
bool catch_auto_run
Run w/o command-line args, i.e.
int nop() const noexcept
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:53
std::string to_decstring(const value_type &v, const char separator=',', const nsize_t width=0) noexcept
Produce a decimal string representation of an integral integer value.
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
Definition: backtrace.hpp:32
bool next() noexcept
A simple allocator using POSIX C functions: ::malloc(), ::free() and ::realloc().
Definition: callocator.hpp:50
template< class T > is_cow_type<T>::value compile-time Type Trait, determining whether the given temp...
template< class T > is_darray_type<T>::value compile-time Type Trait, determining whether the given t...
Definition: darray.hpp:1453
static void test_00_seq_fill_unique_idx(T &data, const Size_type size)
static bool equal_comparator(const value_type &a, const value_type &b)
static bool test_01_seq_fill_list_footprint(const std::string &type_id, const Size_type size0, const Size_type reserve0, const bool do_print_mem)
static bool test_02_seq_fillunique_find_itr(const std::string &type_id, const Size_type size0, const Size_type reserve0)
static void print_mem(const std::string &pre, const T &data)
static void print_container_info(const std::string &type_id, const Cont &c, std::enable_if_t< jau::is_darray_type< Cont >::value, bool >=true)
static bool benchmark_fillseq_list_itr(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
static bool benchmark_fillseq_list_idx(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
const DataType01 * findDataSet01_idx(T &data, DataType01 const &elem) noexcept
static void test_00_seq_fill_unique_itr(T &data, const Size_type size, std::enable_if_t< is_cow_type< T >::value, bool >=true)
static bool test_01_seq_fill_list_idx(const std::string &type_id, const Size_type size0, const Size_type reserve0)
static void test_00_seq_fill(T &data, const Size_type size)
const DataType01 * findDataSet01_itr(T &data, DataType01 const &elem, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
static int test_00_list_idx(T &data)
static bool benchmark_fillunique_find_itr(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
static uint8_t start_addr_b[]
static void test_00_seq_find_idx(T &data)
static bool test_01_seq_fill_list_itr(const std::string &type_id, const Size_type size0, const Size_type reserve0)
static bool benchmark_fillunique_find_idx(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
static bool footprint_fillseq_list_itr(const std::string &type_id, const bool do_rserv)
static int test_00_list_itr(T &data, std::enable_if_t< is_cow_type< T >::value, bool >=true)
static bool test_02_seq_fillunique_find_idx(const std::string &type_id, const Size_type size0, const Size_type reserve0)
static void test_00_seq_find_itr(T &data)
static Addr48Bit start_addr(start_addr_b)
TEST_CASE("Memory Footprint 01 - Fill Sequential and List", "[datatype][footprint]")
int printf(const char *format,...)
Operating Systems predefined macros.