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 printf(
"Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
297 bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
306template<
class T,
typename Size_type>
310 REQUIRE(data.size() == 0);
313 data.reserve(reserve0);
314 REQUIRE(data.size() == 0);
315 REQUIRE(data.capacity() == reserve0);
319 REQUIRE(data.size() == size0);
320 REQUIRE(data.capacity() >= size0);
323 REQUIRE(data.size() == size0);
324 REQUIRE(data.capacity() >= size0);
327 REQUIRE(data.size() == 0);
328 return data.size() == 0;
331template<
class T,
typename Size_type>
334 REQUIRE(0 == data.get_allocator().memory_usage);
335 REQUIRE(data.size() == 0);
339 data.reserve(reserve0);
340 REQUIRE(data.size() == 0);
341 REQUIRE(0 != data.get_allocator().memory_usage);
342 REQUIRE(data.capacity() == reserve0);
346 REQUIRE(0 != data.get_allocator().memory_usage);
347 REQUIRE(data.size() == size0);
348 REQUIRE(data.capacity() >= size0);
351 REQUIRE(0 != data.get_allocator().memory_usage);
352 REQUIRE(data.size() == size0);
353 REQUIRE(data.capacity() >= size0);
354 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
357 REQUIRE(data.size() == 0);
360 return data.size() == 0;
363template<
class T,
typename Size_type>
367 REQUIRE(data.size() == 0);
370 data.reserve(reserve0);
371 REQUIRE(data.size() == 0);
372 REQUIRE(data.capacity() == reserve0);
376 REQUIRE(data.size() == size0);
377 REQUIRE(data.capacity() >= size0);
380 REQUIRE(data.size() == size0);
381 REQUIRE(data.capacity() >= size0);
384 REQUIRE(data.size() == 0);
385 return data.size() == 0;
388template<
class T,
typename Size_type>
392 REQUIRE(data.size() == 0);
395 data.reserve(reserve0);
396 REQUIRE(data.size() == 0);
397 REQUIRE(data.capacity() == reserve0);
401 REQUIRE(data.size() == size0);
402 REQUIRE(data.capacity() >= size0);
405 REQUIRE(data.size() == size0);
406 REQUIRE(data.capacity() >= size0);
409 REQUIRE(data.size() == 0);
410 return data.size() == 0;
412template<
class T,
typename Size_type>
416 REQUIRE(data.size() == 0);
419 data.reserve(reserve0);
420 REQUIRE(data.size() == 0);
421 REQUIRE(data.capacity() == reserve0);
425 REQUIRE(data.size() == size0);
426 REQUIRE(data.capacity() >= size0);
429 REQUIRE(data.size() == size0);
430 REQUIRE(data.capacity() >= size0);
433 REQUIRE(data.size() == 0);
434 return data.size() == 0;
440template<
class T,
typename Size_type>
448 if( !catch_auto_run ) {
455template<
class T,
typename Size_type>
457 const bool do_rserv) {
458#if RUN_INDEXED_BENCHMARK
463 if( catch_perf_analysis ) {
464 BENCHMARK(title_pre+
" FillSeq_List 1000") {
469 if( catch_auto_run ) {
476 BENCHMARK(title_pre+
" FillSeq_List 50") {
479 BENCHMARK(title_pre+
" FillSeq_List 100") {
482 BENCHMARK(title_pre+
" FillSeq_List 1000") {
492template<
class T,
typename Size_type>
494 const bool do_rserv) {
499 if( catch_perf_analysis ) {
500 BENCHMARK(title_pre+
" FillSeq_List 1000") {
506 if( catch_auto_run ) {
513 BENCHMARK(title_pre+
" FillSeq_List 50") {
516 BENCHMARK(title_pre+
" FillSeq_List 100") {
519 BENCHMARK(title_pre+
" FillSeq_List 1000") {
525template<
class T,
typename Size_type>
527 const bool do_rserv) {
528#if RUN_INDEXED_BENCHMARK
533 if( catch_perf_analysis ) {
534 BENCHMARK(title_pre+
" FillUni_List 1000") {
539 if( catch_auto_run ) {
546 BENCHMARK(title_pre+
" FillUni_List 50") {
549 BENCHMARK(title_pre+
" FillUni_List 100") {
552 BENCHMARK(title_pre+
" FillUni_List 1000") {
562template<
class T,
typename Size_type>
564 const bool do_rserv) {
569 if( catch_perf_analysis ) {
570 BENCHMARK(title_pre+
" FillUni_List 1000") {
576 if( catch_auto_run ) {
583 BENCHMARK(title_pre+
" FillUni_List 50") {
586 BENCHMARK(title_pre+
" FillUni_List 100") {
589 BENCHMARK(title_pre+
" FillUni_List 1000") {
598TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
599 if( catch_perf_analysis ) {
611#if RUN_RESERVE_BENCHMARK
621TEST_CASE(
"Perf Test 01 - Fill Sequential and List, empty and reserve",
"[datatype][sequential]" ) {
622 if( catch_perf_analysis ) {
628#if RUN_RESERVE_BENCHMARK
648#if RUN_RESERVE_BENCHMARK
658TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
659 if( catch_perf_analysis ) {
663#if RUN_RESERVE_BENCHMARK
683#if RUN_RESERVE_BENCHMARK
uint_fast32_t nsize_t
Natural 'size_t' alternative using uint_fast32_t as its natural sized type.
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.
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 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)
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 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.