28#include <jau/test/catch2_ext.hpp>
46#define RUN_RESERVE_BENCHMARK 0
47#define RUN_INDEXED_BENCHMARK 0
56 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 std::is_trivially_copyable_v<typename Cont::value_type>,
70 printf(
"\nContainer Type %s (!darray, a cow %d); size %d bytes\n",
77static uint8_t
start_addr_b[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
83template<
class T,
typename Size_type>
85 const Size_type size = data.size();
86 for (Size_type i = 0; i < size; ++i) {
95template<
class T,
typename Size_type>
98 const Size_type size = data.size();
99 for (Size_type i = 0; i < size; ++i) {
101 some_number += e.
nop();
103 REQUIRE(some_number > 0);
107template<
class T,
typename Size_type>
111 typename T::const_iterator first = data.cbegin();
112 for (; !first.is_end(); ++first) {
113 if (*first == elem) {
119template<
class T,
typename Size_type>
123 typename T::const_iterator first = data.cbegin();
124 typename T::const_iterator last = data.cend();
125 for (; first != last; ++first) {
126 if (*first == elem) {
138 typename T::const_iterator first = data.cbegin();
139 for (; !first.is_end(); ++first) {
140 some_number += (*first).nop();
142 REQUIRE(some_number > 0);
151 typename T::const_iterator first = data.cbegin();
152 typename T::const_iterator last = data.cend();
153 for (; first != last; ++first) {
154 some_number += (*first).nop();
156 REQUIRE(some_number > 0);
161template<
class T,
typename Size_type>
164 const Size_type size = data.size();
165 Size_type fi = 0, i=0;
167 for(; i<size && a0.
next(); ++i) {
170 if(
nullptr != found ) {
178template<
class T,
typename Size_type>
181 const Size_type size = data.size();
182 Size_type fi = 0, i=0;
184 for(; i<size && a0.
next(); ++i) {
187 if(
nullptr != found ) {
195template<
class T,
typename Size_type>
200 for(; i<size && a0.
next(); ++i) {
201 data.emplace_back( a0,
static_cast<uint8_t
>(1) );
203 REQUIRE(i == data.size());
206template<
class T,
typename Size_type>
211 for(; i<size && a0.
next(); ++i) {
214 if(
nullptr == exist ) {
215 data.push_back( std::move( elem ) );
219 REQUIRE(i == data.size());
223template<
class value_type>
228template<
class T,
typename Size_type>
236 typename T::iterator first = data.begin();
238 for(; i<size && a0.
next(); ++i, first.to_begin()) {
240 for (; !first.is_end(); ++first) {
241 if (*first == elem) {
245 if( first.is_end() ) {
246 first.push_back( std::move( elem ) );
252 for(; i<size && a0.
next(); ++i) {
253 if( data.push_back_unique(
DataType01(a0,
static_cast<uint8_t
>(1)),
259 REQUIRE(i == data.size());
263template<
class T,
typename Size_type>
270 for(; i<size && a0.
next(); ++i) {
272 typename T::const_iterator first = data.cbegin();
273 typename T::const_iterator last = data.cend();
274 for (; first != last; ++first) {
275 if (*first == elem) {
279 if( first == last ) {
280 data.push_back( std::move( elem ) );
284 REQUIRE(i == data.size());
289static void print_mem(
const std::string& pre,
const T& data) {
290 std::size_t bytes_element =
sizeof(
DataType01);
291 std::size_t elements = data.size();
292 std::size_t bytes_net = elements * bytes_element;
293 std::size_t bytes_total = data.get_allocator().memory_usage;
294 double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (double)bytes_net );
295 jau_printf(
"Mem: %s: Elements %'5zu x %zu bytes; %s, %lf ratio\n",
296 pre.c_str(), elements, bytes_element, data.get_allocator().toString(), overhead);
305template<
class T,
typename Size_type>
309 REQUIRE(data.size() == 0);
312 data.reserve(reserve0);
313 REQUIRE(data.size() == 0);
314 REQUIRE(data.capacity() == reserve0);
318 REQUIRE(data.size() == size0);
319 REQUIRE(data.capacity() >= size0);
322 REQUIRE(data.size() == size0);
323 REQUIRE(data.capacity() >= size0);
326 REQUIRE(data.size() == 0);
327 return data.size() == 0;
330template<
class T,
typename Size_type>
333 REQUIRE(0 == data.get_allocator().memory_usage);
334 REQUIRE(data.size() == 0);
338 data.reserve(reserve0);
339 REQUIRE(data.size() == 0);
340 REQUIRE(0 != data.get_allocator().memory_usage);
341 REQUIRE(data.capacity() == reserve0);
345 REQUIRE(0 != data.get_allocator().memory_usage);
346 REQUIRE(data.size() == size0);
347 REQUIRE(data.capacity() >= size0);
350 REQUIRE(0 != data.get_allocator().memory_usage);
351 REQUIRE(data.size() == size0);
352 REQUIRE(data.capacity() >= size0);
353 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
356 REQUIRE(data.size() == 0);
359 return data.size() == 0;
362template<
class T,
typename Size_type>
366 REQUIRE(data.size() == 0);
369 data.reserve(reserve0);
370 REQUIRE(data.size() == 0);
371 REQUIRE(data.capacity() == reserve0);
375 REQUIRE(data.size() == size0);
376 REQUIRE(data.capacity() >= size0);
379 REQUIRE(data.size() == size0);
380 REQUIRE(data.capacity() >= size0);
383 REQUIRE(data.size() == 0);
384 return data.size() == 0;
387template<
class T,
typename Size_type>
391 REQUIRE(data.size() == 0);
394 data.reserve(reserve0);
395 REQUIRE(data.size() == 0);
396 REQUIRE(data.capacity() == reserve0);
400 REQUIRE(data.size() == size0);
401 REQUIRE(data.capacity() >= size0);
404 REQUIRE(data.size() == size0);
405 REQUIRE(data.capacity() >= size0);
408 REQUIRE(data.size() == 0);
409 return data.size() == 0;
411template<
class T,
typename Size_type>
415 REQUIRE(data.size() == 0);
418 data.reserve(reserve0);
419 REQUIRE(data.size() == 0);
420 REQUIRE(data.capacity() == reserve0);
424 REQUIRE(data.size() == size0);
425 REQUIRE(data.capacity() >= size0);
428 REQUIRE(data.size() == size0);
429 REQUIRE(data.capacity() >= size0);
432 REQUIRE(data.size() == 0);
433 return data.size() == 0;
439template<
class T,
typename Size_type>
447 if( !catch_auto_run ) {
454template<
class T,
typename Size_type>
456 const bool do_rserv) {
457#if RUN_INDEXED_BENCHMARK
462 if( catch_perf_analysis ) {
463 BENCHMARK(title_pre+
" FillSeq_List 1000") {
468 if( catch_auto_run ) {
475 BENCHMARK(title_pre+
" FillSeq_List 50") {
478 BENCHMARK(title_pre+
" FillSeq_List 100") {
481 BENCHMARK(title_pre+
" FillSeq_List 1000") {
491template<
class T,
typename Size_type>
493 const bool do_rserv) {
498 if( catch_perf_analysis ) {
499 BENCHMARK(title_pre+
" FillSeq_List 1000") {
505 if( catch_auto_run ) {
512 BENCHMARK(title_pre+
" FillSeq_List 50") {
515 BENCHMARK(title_pre+
" FillSeq_List 100") {
518 BENCHMARK(title_pre+
" FillSeq_List 1000") {
524template<
class T,
typename Size_type>
526 const bool do_rserv) {
527#if RUN_INDEXED_BENCHMARK
532 if( catch_perf_analysis ) {
533 BENCHMARK(title_pre+
" FillUni_List 1000") {
538 if( catch_auto_run ) {
545 BENCHMARK(title_pre+
" FillUni_List 50") {
548 BENCHMARK(title_pre+
" FillUni_List 100") {
551 BENCHMARK(title_pre+
" FillUni_List 1000") {
561template<
class T,
typename Size_type>
563 const bool do_rserv) {
568 if( catch_perf_analysis ) {
569 BENCHMARK(title_pre+
" FillUni_List 1000") {
575 if( catch_auto_run ) {
582 BENCHMARK(title_pre+
" FillUni_List 50") {
585 BENCHMARK(title_pre+
" FillUni_List 100") {
588 BENCHMARK(title_pre+
" FillUni_List 1000") {
597TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
598 if( catch_perf_analysis ) {
610#if RUN_RESERVE_BENCHMARK
620TEST_CASE(
"Perf Test 01 - Fill Sequential and List, empty and reserve",
"[datatype][sequential]" ) {
621 if( catch_perf_analysis ) {
627#if RUN_RESERVE_BENCHMARK
647#if RUN_RESERVE_BENCHMARK
657TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
658 if( catch_perf_analysis ) {
662#if RUN_RESERVE_BENCHMARK
682#if RUN_RESERVE_BENCHMARK
#define jau_printf(fmt,...)
uint_bytes_t< sizeof(unsigned long int)> nsize_t
Natural 'size_t' alternative using uint<XX>_t with xx = sizeof(unsigned long int)*8 as its natural si...
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
A simple allocator using POSIX C functions: ::malloc(), ::free() and ::realloc().
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...
static const DataType01 * findDataSet01_itr(T &data, DataType01 const &elem, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
static const DataType01 * findDataSet01_idx(T &data, DataType01 const &elem) noexcept
static void test_00_seq_fill_unique_idx(T &data, const Size_type size)
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)
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)
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 equal_comparator(const value_type &a, const value_type &b) noexcept
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.