Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
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 <iostream>
25 #include <cassert>
26 #include <cinttypes>
27 #include <cstring>
28 #include <random>
29 #include <vector>
30 
31 #define CATCH_CONFIG_RUNNER
32 // #define CATCH_CONFIG_MAIN
33 #include <catch2/catch_amalgamated.hpp>
34 #include <jau/test/catch2_ext.hpp>
35 
36 #include "test_datatype01.hpp"
37 
38 #include <jau/basic_types.hpp>
39 #include <jau/basic_algos.hpp>
40 #include <jau/darray.hpp>
41 #include <jau/cow_darray.hpp>
42 #include <jau/cow_vector.hpp>
44 #include <jau/callocator.hpp>
46 
47 /**
48  * Performance test of jau::darray, jau::cow_darray and jau::cow_vector.
49  */
50 using namespace jau;
51 
52 #define RUN_RESERVE_BENCHMARK 0
53 #define RUN_INDEXED_BENCHMARK 0
54 
55 /****************************************************************************************
56  ****************************************************************************************/
57 
58 template< class Cont >
59 static void print_container_info(const std::string& type_id, const Cont &c,
60  std::enable_if_t< jau::is_darray_type<Cont>::value, bool> = true )
61 {
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",
63  type_id.c_str(), jau::is_cow_type<Cont>::value,
64  Cont::uses_memmove,
65  std::is_trivially_copyable<typename Cont::value_type>::value,
66  Cont::uses_realloc,
67  std::is_base_of<jau::callocator<typename Cont::value_type>, typename Cont::allocator_type>::value,
68  (int)sizeof(c));
69 }
70 
71 template<class Cont>
72 static void print_container_info(const std::string& type_id, const Cont &c,
73  std::enable_if_t< !jau::is_darray_type<Cont>::value, bool> = true )
74 {
75  printf("\nContainer Type %s (!darray, a cow %d); size %d bytes\n",
76  type_id.c_str(), jau::is_cow_type<Cont>::value, (int)sizeof(c));
77 }
78 
79 /****************************************************************************************
80  ****************************************************************************************/
81 
82 static uint8_t start_addr_b[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
84 
85 /****************************************************************************************
86  ****************************************************************************************/
87 
88 template<class T, typename Size_type>
89 const DataType01 * findDataSet01_idx(T& data, DataType01 const & elem) noexcept {
90  const Size_type size = data.size();
91  for (Size_type i = 0; i < size; ++i) {
92  DataType01 & e = data[i];
93  if ( elem == e ) {
94  return &e;
95  }
96  }
97  return nullptr;
98 }
99 
100 template<class T, typename Size_type>
101 static int test_00_list_idx(T& data) {
102  int some_number = 0; // add some validated work, avoiding any 'optimization away'
103  const Size_type size = data.size();
104  for (Size_type i = 0; i < size; ++i) {
105  const DataType01 & e = data[i];
106  some_number += e.nop();
107  }
108  REQUIRE(some_number > 0);
109  return some_number;
110 }
111 
112 template<class T, typename Size_type>
113 const DataType01 * findDataSet01_itr(T& data, DataType01 const & elem,
114  std::enable_if_t< is_cow_type<T>::value, bool> = true) noexcept
115 {
116  typename T::const_iterator first = data.cbegin();
117  for (; !first.is_end(); ++first) {
118  if (*first == elem) {
119  return &(*first);
120  }
121  }
122  return nullptr;
123 }
124 template<class T, typename Size_type>
125 const DataType01 * findDataSet01_itr(T& data, DataType01 const & elem,
126  std::enable_if_t< !is_cow_type<T>::value, bool> = true) noexcept
127 {
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) {
132  return &(*first);
133  }
134  }
135  return nullptr;
136 }
137 
138 template<class T>
139 static int test_00_list_itr(T& data,
140  std::enable_if_t< is_cow_type<T>::value, bool> = true )
141 {
142  int some_number = 0; // add some validated work, avoiding any 'optimization away'
143  typename T::const_iterator first = data.cbegin();
144  for (; !first.is_end(); ++first) {
145  some_number += (*first).nop();
146  }
147  REQUIRE(some_number > 0);
148  return some_number;
149 }
150 
151 template<class T>
152 static int test_00_list_itr(T& data,
153  std::enable_if_t< !is_cow_type<T>::value, bool> = true )
154 {
155  int some_number = 0; // add some validated work, avoiding any 'optimization away'
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();
160  }
161  REQUIRE(some_number > 0);
162  return some_number;
163 }
164 
165 
166 template<class T, typename Size_type>
167 static void test_00_seq_find_idx(T& data) {
168  Addr48Bit a0(start_addr);
169  const Size_type size = data.size();
170  Size_type fi = 0, i=0;
171 
172  for(; i<size && a0.next(); ++i) {
173  DataType01 elem(a0, static_cast<uint8_t>(1));
174  const DataType01 *found = findDataSet01_idx<T, Size_type>(data, elem);
175  if( nullptr != found ) {
176  ++fi;
177  found->nop();
178  }
179  }
180  REQUIRE(fi == i);
181 }
182 
183 template<class T, typename Size_type>
184 static void test_00_seq_find_itr(T& data) {
185  Addr48Bit a0(start_addr);
186  const Size_type size = data.size();
187  Size_type fi = 0, i=0;
188 
189  for(; i<size && a0.next(); ++i) {
190  DataType01 elem(a0, static_cast<uint8_t>(1));
191  const DataType01 *found = findDataSet01_itr<T, Size_type>(data, elem);
192  if( nullptr != found ) {
193  ++fi;
194  found->nop();
195  }
196  }
197  REQUIRE(fi == i);
198 }
199 
200 template<class T, typename Size_type>
201 static void test_00_seq_fill(T& data, const Size_type size) {
202  Addr48Bit a0(start_addr);
203  Size_type i=0;
204 
205  for(; i<size && a0.next(); ++i) {
206  data.emplace_back( a0, static_cast<uint8_t>(1) );
207  }
208  REQUIRE(i == data.size());
209 }
210 
211 template<class T, typename Size_type>
212 static void test_00_seq_fill_unique_idx(T& data, const Size_type size) {
213  Addr48Bit a0(start_addr);
214  Size_type i=0, fi=0;
215 
216  for(; i<size && a0.next(); ++i) {
217  DataType01 elem(a0, static_cast<uint8_t>(1));
218  const DataType01* exist = findDataSet01_idx<T, Size_type>(data, elem);
219  if( nullptr == exist ) {
220  data.push_back( std::move( elem ) );
221  ++fi;
222  }
223  }
224  REQUIRE(i == data.size());
225  REQUIRE(fi == size);
226 }
227 
228 template<class value_type>
229 static bool equal_comparator(const value_type& a, const value_type& b) {
230  return a == b;
231 }
232 
233 template<class T, typename Size_type>
234 static void test_00_seq_fill_unique_itr(T& data, const Size_type size,
235  std::enable_if_t< is_cow_type<T>::value, bool> = true) noexcept
236 {
237  Addr48Bit a0(start_addr);
238  Size_type i=0, fi=0;
239 
240 #if 0
241  typename T::iterator first = data.begin();
242 
243  for(; i<size && a0.next(); ++i, first.to_begin()) {
244  DataType01 elem(a0, static_cast<uint8_t>(1));
245  for (; !first.is_end(); ++first) {
246  if (*first == elem) {
247  break;
248  }
249  }
250  if( first.is_end() ) {
251  first.push_back( std::move( elem ) );
252  ++fi;
253  }
254  }
255  first.write_back();
256 #else
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> ) ) {
260  ++fi;
261  }
262  }
263 #endif
264  REQUIRE(i == data.size());
265  REQUIRE(fi == size);
266 }
267 
268 template<class T, typename Size_type>
269 static void test_00_seq_fill_unique_itr(T& data, const Size_type size,
270  std::enable_if_t< !is_cow_type<T>::value, bool> = true) noexcept
271 {
272  Addr48Bit a0(start_addr);
273  Size_type i=0, fi=0;
274 
275  for(; i<size && a0.next(); ++i) {
276  DataType01 elem(a0, static_cast<uint8_t>(1));
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) {
281  break;
282  }
283  }
284  if( first == last ) {
285  data.push_back( std::move( elem ) );
286  ++fi;
287  }
288  }
289  REQUIRE(i == data.size());
290  REQUIRE(fi == size);
291 }
292 
293 template<class T>
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",
301  pre.c_str(), to_decstring(elements, ',', 5).c_str(),
302  bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
303  // 5: 1,000
304  // 7: 100,000
305  // 9: 1,000,000
306 }
307 
308 /****************************************************************************************
309  ****************************************************************************************/
310 
311 template<class T, typename Size_type>
312 static bool test_01_seq_fill_list_idx(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
313  (void)type_id;
314  T data;
315  REQUIRE(data.size() == 0);
316 
317  if( 0 < reserve0 ) {
318  data.reserve(reserve0);
319  REQUIRE(data.size() == 0);
320  REQUIRE(data.capacity() == reserve0);
321  }
322 
323  test_00_seq_fill<T, Size_type>(data, size0);
324  REQUIRE(data.size() == size0);
325  REQUIRE(data.capacity() >= size0);
326 
327  test_00_list_idx<T, Size_type>(data);
328  REQUIRE(data.size() == size0);
329  REQUIRE(data.capacity() >= size0);
330 
331  data.clear();
332  REQUIRE(data.size() == 0);
333  return data.size() == 0;
334 }
335 
336 template<class T, typename Size_type>
337 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) {
338  T data;
339  REQUIRE(0 == data.get_allocator().memory_usage);
340  REQUIRE(data.size() == 0);
341  // if( do_print_mem ) { print_mem(type_id+" 01 (empty)", data); }
342 
343  if( 0 < reserve0 ) {
344  data.reserve(reserve0);
345  REQUIRE(data.size() == 0);
346  REQUIRE(0 != data.get_allocator().memory_usage);
347  REQUIRE(data.capacity() == reserve0);
348  }
349 
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);
354 
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); }
360 
361  data.clear();
362  REQUIRE(data.size() == 0);
363  // if( do_print_mem ) { print_mem(type_id+" 01 (clear)", data); }
364  // REQUIRE(0 == data.get_allocator().memory_usage);
365  return data.size() == 0;
366 }
367 
368 template<class T, typename Size_type>
369 static bool test_01_seq_fill_list_itr(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
370  (void)type_id;
371  T data;
372  REQUIRE(data.size() == 0);
373 
374  if( 0 < reserve0 ) {
375  data.reserve(reserve0);
376  REQUIRE(data.size() == 0);
377  REQUIRE(data.capacity() == reserve0);
378  }
379 
380  test_00_seq_fill<T, Size_type>(data, size0);
381  REQUIRE(data.size() == size0);
382  REQUIRE(data.capacity() >= size0);
383 
384  test_00_list_itr<T>(data);
385  REQUIRE(data.size() == size0);
386  REQUIRE(data.capacity() >= size0);
387 
388  data.clear();
389  REQUIRE(data.size() == 0);
390  return data.size() == 0;
391 }
392 
393 template<class T, typename Size_type>
394 static bool test_02_seq_fillunique_find_idx(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
395  (void)type_id;
396  T data;
397  REQUIRE(data.size() == 0);
398 
399  if( 0 < reserve0 ) {
400  data.reserve(reserve0);
401  REQUIRE(data.size() == 0);
402  REQUIRE(data.capacity() == reserve0);
403  }
404 
405  test_00_seq_fill_unique_idx<T, Size_type>(data, size0);
406  REQUIRE(data.size() == size0);
407  REQUIRE(data.capacity() >= size0);
408 
409  test_00_seq_find_idx<T, Size_type>(data);
410  REQUIRE(data.size() == size0);
411  REQUIRE(data.capacity() >= size0);
412 
413  data.clear();
414  REQUIRE(data.size() == 0);
415  return data.size() == 0;
416 }
417 template<class T, typename Size_type>
418 static bool test_02_seq_fillunique_find_itr(const std::string& type_id, const Size_type size0, const Size_type reserve0) {
419  (void)type_id;
420  T data;
421  REQUIRE(data.size() == 0);
422 
423  if( 0 < reserve0 ) {
424  data.reserve(reserve0);
425  REQUIRE(data.size() == 0);
426  REQUIRE(data.capacity() == reserve0);
427  }
428 
429  test_00_seq_fill_unique_itr<T, Size_type>(data, size0);
430  REQUIRE(data.size() == size0);
431  REQUIRE(data.capacity() >= size0);
432 
433  test_00_seq_find_itr<T, Size_type>(data);
434  REQUIRE(data.size() == size0);
435  REQUIRE(data.capacity() >= size0);
436 
437  data.clear();
438  REQUIRE(data.size() == 0);
439  return data.size() == 0;
440 }
441 
442 /****************************************************************************************
443  ****************************************************************************************/
444 
445 template<class T, typename Size_type>
446 static bool footprint_fillseq_list_itr(const std::string& type_id, const bool do_rserv) {
447  {
448  T data;
449  print_container_info(type_id, data);
450  }
451  // test_01_seq_fill_list_footprint<T, Size_type>(type_id, 25, do_rserv? 25 : 0, true);
452  test_01_seq_fill_list_footprint<T, Size_type>(type_id, 50, do_rserv? 50 : 0, true);
453  if( !catch_auto_run ) {
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);
456  }
457  return true;
458 }
459 
460 template<class T, typename Size_type>
461 static bool benchmark_fillseq_list_idx(const std::string& title_pre, const std::string& type_id,
462  const bool do_rserv) {
463 #if RUN_INDEXED_BENCHMARK
464  {
465  T data;
466  print_container_info(title_pre, data);
467  }
468  if( catch_perf_analysis ) {
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);
471  };
472  return true;
473  }
474  if( catch_auto_run ) {
475  test_01_seq_fill_list_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
476  return true;
477  }
478  // BENCHMARK(title_pre+" FillSeq_List 25") {
479  // return test_01_seq_fill_list_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
480  // };
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);
483  };
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);
486  };
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);
489  };
490 #else
491  (void) title_pre;
492  (void) type_id;
493  (void) do_rserv;
494 #endif
495  return true;
496 }
497 template<class T, typename Size_type>
498 static bool benchmark_fillseq_list_itr(const std::string& title_pre, const std::string& type_id,
499  const bool do_rserv) {
500  {
501  T data;
502  print_container_info(title_pre, data);
503  }
504  if( catch_perf_analysis ) {
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);
507  };
508  // test_01_seq_fill_list_itr<T, Size_type>(type_id, 100000, do_rserv? 100000 : 0);
509  return true;
510  }
511  if( catch_auto_run ) {
512  test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
513  return true;
514  }
515  // BENCHMARK(title_pre+" FillSeq_List 25") {
516  // return test_01_seq_fill_list_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
517  // };
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);
520  };
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);
523  };
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);
526  };
527  return true;
528 }
529 
530 template<class T, typename Size_type>
531 static bool benchmark_fillunique_find_idx(const std::string& title_pre, const std::string& type_id,
532  const bool do_rserv) {
533 #if RUN_INDEXED_BENCHMARK
534  {
535  T data;
536  print_container_info(title_pre, data);
537  }
538  if( catch_perf_analysis ) {
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);
541  };
542  return true;
543  }
544  if( catch_auto_run ) {
545  test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
546  return true;
547  }
548  // BENCHMARK(title_pre+" FillUni_List 25") {
549  // return test_02_seq_fillunique_find_idx<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
550  // };
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);
553  };
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);
556  };
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);
559  };
560 #else
561  (void) title_pre;
562  (void) type_id;
563  (void) do_rserv;
564 #endif
565  return true;
566 }
567 template<class T, typename Size_type>
568 static bool benchmark_fillunique_find_itr(const std::string& title_pre, const std::string& type_id,
569  const bool do_rserv) {
570  {
571  T data;
572  print_container_info(title_pre, data);
573  }
574  if( catch_perf_analysis ) {
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);
577  };
578  // test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100000, do_rserv? 100000 : 0);
579  return true;
580  }
581  if( catch_auto_run ) {
582  test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
583  return true;
584  }
585  // BENCHMARK(title_pre+" FillUni_List 25") {
586  // return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 25, do_rserv? 25 : 0);
587  // };
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);
590  };
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);
593  };
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);
596  };
597  return true;
598 }
599 
600 /****************************************************************************************
601  ****************************************************************************************/
602 
603 TEST_CASE( "Memory Footprint 01 - Fill Sequential and List", "[datatype][footprint]" ) {
604  if( catch_perf_analysis ) {
605  // footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>("cowstdvec_empty_", false);
606  // footprint_fillseq_list_itr< jau::cow_darray<DataType01, counting_callocator<DataType01>, jau::nsize_t>, jau::nsize_t>("cowdarray_empty_", false);
607  return;
608  }
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);
615 
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);
623 #endif
624 }
625 
626 TEST_CASE( "Perf Test 01 - Fill Sequential and List, empty and reserve", "[datatype][sequential]" ) {
627  if( catch_perf_analysis ) {
628  // benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
629  // benchmark_fillseq_list_itr< jau::darray<DataType01, jau::callocator<DataType01>, jau::nsize_t>, jau::nsize_t>("JAU_DArray_def_empty_itr", "darray_empty_", false);
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);
637 #endif
638  return;
639  }
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);
642 
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);
647 
648  benchmark_fillseq_list_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
649 
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);
652 
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);
660 #endif
661 }
662 
663 TEST_CASE( "Perf Test 02 - Fill Unique and List, empty and reserve", "[datatype][unique]" ) {
664  if( catch_perf_analysis ) {
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);
672 #endif
673  return;
674  }
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);
677 
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);
682 
683  benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>("COW_Vector_def_empty_itr", "cowstdvec_empty_", false);
684 
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);
687 
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);
695 #endif
696 }
697 
callocator.hpp
test_00_seq_find_idx
static void test_00_seq_find_idx(T &data)
Definition: test_cow_darray_perf01.cpp:167
test_02_seq_fillunique_find_idx
static bool test_02_seq_fillunique_find_idx(const std::string &type_id, const Size_type size0, const Size_type reserve0)
Definition: test_cow_darray_perf01.cpp:394
jau::to_decstring
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.
Definition: string_util.hpp:143
test_01_seq_fill_list_itr
static bool test_01_seq_fill_list_itr(const std::string &type_id, const Size_type size0, const Size_type reserve0)
Definition: test_cow_darray_perf01.cpp:369
catch_auto_run
bool catch_auto_run
Run w/o command-line args, i.e.
Definition: catch2_my_main.cpp:39
test_00_list_idx
static int test_00_list_idx(T &data)
Definition: test_cow_darray_perf01.cpp:101
test_00_list_itr
static int test_00_list_itr(T &data, std::enable_if_t< is_cow_type< T >::value, bool >=true)
Definition: test_cow_darray_perf01.cpp:139
darray.hpp
counting_callocator.hpp
basic_algos.hpp
jau::is_darray_type
template< class T > is_darray_type<T>::value compile-time Type Trait, determining whether the given t...
Definition: darray.hpp:1206
findDataSet01_idx
const DataType01 * findDataSet01_idx(T &data, DataType01 const &elem) noexcept
Definition: test_cow_darray_perf01.cpp:89
benchmark_fillseq_list_itr
static bool benchmark_fillseq_list_itr(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
Definition: test_cow_darray_perf01.cpp:498
jau
Definition: basic_algos.hpp:34
jau::is_cow_type
template< class T > is_cow_type<T>::value compile-time Type Trait, determining whether the given temp...
Definition: cow_iterator.hpp:1039
print_container_info
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)
Definition: test_cow_darray_perf01.cpp:59
print_mem
static void print_mem(const std::string &pre, const T &data)
Definition: test_cow_darray_perf01.cpp:294
cow_darray.hpp
benchmark_fillunique_find_idx
static bool benchmark_fillunique_find_idx(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
Definition: test_cow_darray_perf01.cpp:531
test_datatype01.hpp
start_addr
static Addr48Bit start_addr(start_addr_b)
cow_vector.hpp
equal_comparator
static bool equal_comparator(const value_type &a, const value_type &b)
Definition: test_cow_darray_perf01.cpp:229
footprint_fillseq_list_itr
static bool footprint_fillseq_list_itr(const std::string &type_id, const bool do_rserv)
Definition: test_cow_darray_perf01.cpp:446
test_01_seq_fill_list_footprint
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)
Definition: test_cow_darray_perf01.cpp:337
findDataSet01_itr
const DataType01 * findDataSet01_itr(T &data, DataType01 const &elem, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
Definition: test_cow_darray_perf01.cpp:113
counting_allocator.hpp
benchmark_fillseq_list_idx
static bool benchmark_fillseq_list_idx(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
Definition: test_cow_darray_perf01.cpp:461
TEST_CASE
TEST_CASE("Memory Footprint 01 - Fill Sequential and List", "[datatype][footprint]")
Definition: test_cow_darray_perf01.cpp:603
test_01_seq_fill_list_idx
static bool test_01_seq_fill_list_idx(const std::string &type_id, const Size_type size0, const Size_type reserve0)
Definition: test_cow_darray_perf01.cpp:312
jau::nsize_t
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
Definition: int_types.hpp:44
DataType01
Definition: test_datatype01.hpp:141
DataType01::nop
int nop() const noexcept
Definition: test_datatype01.hpp:173
test_00_seq_fill_unique_itr
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) noexcept
Definition: test_cow_darray_perf01.cpp:234
jau::callocator
A simple allocator using POSIX C functions: ::malloc(), ::free() and ::realloc().
Definition: callocator.hpp:53
test_00_seq_find_itr
static void test_00_seq_find_itr(T &data)
Definition: test_cow_darray_perf01.cpp:184
basic_types.hpp
benchmark_fillunique_find_itr
static bool benchmark_fillunique_find_itr(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
Definition: test_cow_darray_perf01.cpp:568
Addr48Bit
Definition: test_datatype01.hpp:113
catch2_ext.hpp
test_02_seq_fillunique_find_itr
static bool test_02_seq_fillunique_find_itr(const std::string &type_id, const Size_type size0, const Size_type reserve0)
Definition: test_cow_darray_perf01.cpp:418
Addr48Bit::next
bool next() noexcept
Definition: test_datatype01.hpp:113
start_addr_b
static uint8_t start_addr_b[]
Definition: test_cow_darray_perf01.cpp:82
test_00_seq_fill_unique_idx
static void test_00_seq_fill_unique_idx(T &data, const Size_type size)
Definition: test_cow_darray_perf01.cpp:212
catch_perf_analysis
bool catch_perf_analysis
Run w/ command-line arg '–perf_analysis'.
Definition: catch2_my_main.cpp:42
test_00_seq_fill
static void test_00_seq_fill(T &data, const Size_type size)
Definition: test_cow_darray_perf01.cpp:201