#include <cassert>
#include <cstring>
#include <vector>
#include <jau/test/catch2_ext.hpp>
#define RUN_RESERVE_BENCHMARK 0
#define RUN_INDEXED_BENCHMARK 0
template< class Cont >
{
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",
Cont::uses_memmove,
std::is_trivially_copyable_v<typename Cont::value_type>,
Cont::uses_realloc,
Cont::uses_secmem,
(int)sizeof(c));
}
template<class Cont>
{
printf(
"\nContainer Type %s (!darray, a cow %d); size %d bytes\n",
}
static uint8_t
start_addr_b[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
template<class T, typename Size_type>
const Size_type size = data.size();
for (Size_type i = 0; i < size; ++i) {
if ( elem == e ) {
return &e;
}
}
return nullptr;
}
template<class T, typename Size_type>
int some_number = 0;
const Size_type size = data.size();
for (Size_type i = 0; i < size; ++i) {
}
REQUIRE(some_number > 0);
return some_number;
}
template<class T, typename Size_type>
{
typename T::const_iterator first = data.cbegin();
for (; !first.is_end(); ++first) {
if (*first == elem) {
return &(*first);
}
}
return nullptr;
}
template<class T, typename Size_type>
{
typename T::const_iterator first = data.cbegin();
typename T::const_iterator last = data.cend();
for (; first != last; ++first) {
if (*first == elem) {
return &(*first);
}
}
return nullptr;
}
template<class T>
{
int some_number = 0;
typename T::const_iterator first = data.cbegin();
for (; !first.is_end(); ++first) {
some_number += (*first).nop();
}
REQUIRE(some_number > 0);
return some_number;
}
template<class T>
{
int some_number = 0;
typename T::const_iterator first = data.cbegin();
typename T::const_iterator last = data.cend();
for (; first != last; ++first) {
some_number += (*first).nop();
}
REQUIRE(some_number > 0);
return some_number;
}
template<class T, typename Size_type>
const Size_type size = data.size();
Size_type fi = 0, i=0;
for(; i<size && a0.next(); ++i) {
if( nullptr != found ) {
++fi;
}
}
REQUIRE(fi == i);
}
template<class T, typename Size_type>
const Size_type size = data.size();
Size_type fi = 0, i=0;
for(; i<size && a0.next(); ++i) {
if( nullptr != found ) {
++fi;
}
}
REQUIRE(fi == i);
}
template<class T, typename Size_type>
Size_type i=0;
for(; i<size && a0.next(); ++i) {
data.emplace_back( a0, static_cast<uint8_t>(1) );
}
REQUIRE(i == data.size());
}
template<class T, typename Size_type>
Size_type i=0, fi=0;
for(; i<size && a0.next(); ++i) {
if( nullptr == exist ) {
data.push_back( std::move( elem ) );
++fi;
}
}
REQUIRE(i == data.size());
REQUIRE(fi == size);
}
template<class value_type>
static bool equal_comparator(
const value_type& a,
const value_type& b)
noexcept {
return a == b;
}
template<class T, typename Size_type>
{
Size_type i=0, fi=0;
#if 0
typename T::iterator first = data.begin();
for(; i<size && a0.next(); ++i, first.to_begin()) {
for (; !first.is_end(); ++first) {
if (*first == elem) {
break;
}
}
if( first.is_end() ) {
first.push_back( std::move( elem ) );
++fi;
}
}
first.write_back();
#else
for(; i<size && a0.next(); ++i) {
if( data.push_back_unique(
DataType01(a0,
static_cast<uint8_t
>(1)),
++fi;
}
}
#endif
REQUIRE(i == data.size());
REQUIRE(fi == size);
}
template<class T, typename Size_type>
{
Size_type i=0, fi=0;
for(; i<size && a0.next(); ++i) {
typename T::const_iterator first = data.cbegin();
typename T::const_iterator last = data.cend();
for (; first != last; ++first) {
if (*first == elem) {
break;
}
}
if( first == last ) {
data.push_back( std::move( elem ) );
++fi;
}
}
REQUIRE(i == data.size());
REQUIRE(fi == size);
}
template<class T>
static void print_mem(
const std::string& pre,
const T& data) {
std::size_t elements = data.size();
std::size_t bytes_net = elements * bytes_element;
std::size_t bytes_total = data.get_allocator().memory_usage;
double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (double)bytes_net );
printf(
"Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
}
template<class T, typename Size_type>
(void)type_id;
T data;
REQUIRE(data.size() == 0);
if( 0 < reserve0 ) {
data.reserve(reserve0);
REQUIRE(data.size() == 0);
REQUIRE(data.capacity() == reserve0);
}
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
data.clear();
REQUIRE(data.size() == 0);
return data.size() == 0;
}
template<class T, typename Size_type>
T data;
REQUIRE(0 == data.get_allocator().memory_usage);
REQUIRE(data.size() == 0);
if( 0 < reserve0 ) {
data.reserve(reserve0);
REQUIRE(data.size() == 0);
REQUIRE(0 != data.get_allocator().memory_usage);
REQUIRE(data.capacity() == reserve0);
}
REQUIRE(0 != data.get_allocator().memory_usage);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
REQUIRE(0 != data.get_allocator().memory_usage);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
data.clear();
REQUIRE(data.size() == 0);
return data.size() == 0;
}
template<class T, typename Size_type>
(void)type_id;
T data;
REQUIRE(data.size() == 0);
if( 0 < reserve0 ) {
data.reserve(reserve0);
REQUIRE(data.size() == 0);
REQUIRE(data.capacity() == reserve0);
}
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
data.clear();
REQUIRE(data.size() == 0);
return data.size() == 0;
}
template<class T, typename Size_type>
(void)type_id;
T data;
REQUIRE(data.size() == 0);
if( 0 < reserve0 ) {
data.reserve(reserve0);
REQUIRE(data.size() == 0);
REQUIRE(data.capacity() == reserve0);
}
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
data.clear();
REQUIRE(data.size() == 0);
return data.size() == 0;
}
template<class T, typename Size_type>
(void)type_id;
T data;
REQUIRE(data.size() == 0);
if( 0 < reserve0 ) {
data.reserve(reserve0);
REQUIRE(data.size() == 0);
REQUIRE(data.capacity() == reserve0);
}
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
REQUIRE(data.size() == size0);
REQUIRE(data.capacity() >= size0);
data.clear();
REQUIRE(data.size() == 0);
return data.size() == 0;
}
template<class T, typename Size_type>
{
T data;
}
if( !catch_auto_run ) {
}
return true;
}
template<class T, typename Size_type>
const bool do_rserv) {
#if RUN_INDEXED_BENCHMARK
{
T data;
}
if( catch_perf_analysis ) {
BENCHMARK(title_pre+" FillSeq_List 1000") {
};
return true;
}
if( catch_auto_run ) {
return true;
}
BENCHMARK(title_pre+" FillSeq_List 50") {
};
BENCHMARK(title_pre+" FillSeq_List 100") {
};
BENCHMARK(title_pre+" FillSeq_List 1000") {
};
#else
(void) title_pre;
(void) type_id;
(void) do_rserv;
#endif
return true;
}
template<class T, typename Size_type>
const bool do_rserv) {
{
T data;
}
if( catch_perf_analysis ) {
BENCHMARK(title_pre+" FillSeq_List 1000") {
};
return true;
}
if( catch_auto_run ) {
return true;
}
BENCHMARK(title_pre+" FillSeq_List 50") {
};
BENCHMARK(title_pre+" FillSeq_List 100") {
};
BENCHMARK(title_pre+" FillSeq_List 1000") {
};
return true;
}
template<class T, typename Size_type>
const bool do_rserv) {
#if RUN_INDEXED_BENCHMARK
{
T data;
}
if( catch_perf_analysis ) {
BENCHMARK(title_pre+" FillUni_List 1000") {
};
return true;
}
if( catch_auto_run ) {
return true;
}
BENCHMARK(title_pre+" FillUni_List 50") {
};
BENCHMARK(title_pre+" FillUni_List 100") {
};
BENCHMARK(title_pre+" FillUni_List 1000") {
};
#else
(void) title_pre;
(void) type_id;
(void) do_rserv;
#endif
return true;
}
template<class T, typename Size_type>
const bool do_rserv) {
{
T data;
}
if( catch_perf_analysis ) {
BENCHMARK(title_pre+" FillUni_List 1000") {
};
return true;
}
if( catch_auto_run ) {
return true;
}
BENCHMARK(title_pre+" FillUni_List 50") {
};
BENCHMARK(title_pre+" FillUni_List 100") {
};
BENCHMARK(title_pre+" FillUni_List 1000") {
};
return true;
}
TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
if( catch_perf_analysis ) {
return;
}
#if RUN_RESERVE_BENCHMARK
#endif
}
TEST_CASE(
"Perf Test 01 - Fill Sequential and List, empty and reserve",
"[datatype][sequential]" ) {
if( catch_perf_analysis ) {
#if RUN_RESERVE_BENCHMARK
#endif
return;
}
#if RUN_RESERVE_BENCHMARK
#endif
}
TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
if( catch_perf_analysis ) {
#if RUN_RESERVE_BENCHMARK
#endif
return;
}
#if RUN_RESERVE_BENCHMARK
#endif
}
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...
TEST_CASE("Endianess Test 00", "[endian]")
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)
int printf(const char *format,...)
Operating Systems predefined macros.