29#include <unordered_set>
31#include <jau/test/catch2_ext.hpp>
46static uint8_t
start_addr_b[] = {0x20, 0x26, 0x2A, 0x01, 0x20, 0x10};
51 auto search = data.find(elem);
52 if( search != data.end() ) {
62 some_number += e.
nop();
64 REQUIRE(some_number > 0);
68template<
class T,
typename Size_type>
71 const Size_type size = data.size();
72 Size_type fi = 0, i=0;
74 for(; i<size && a0.
next(); ++i) {
77 if(
nullptr != found ) {
88 const std::size_t size = data.size();
89 std::size_t fi = 0, i=0;
91 for(; i<size && a0.
next(); ++i) {
94 if(
nullptr != found ) {
102template<
class T,
typename Size_type>
107 for(; i<size && a0.
next(); ++i) {
108 data.emplace_back( a0,
static_cast<uint8_t
>(1) );
110 REQUIRE(i == data.size());
113template<
class T,
typename Size_type>
118 for(; i<size && a0.
next(); ++i) {
121 if(
nullptr == exist ) {
122 data.push_back( std::move( elem ) );
126 REQUIRE(i == data.size());
133 std::size_t i=0, fi=0;
135 for(; i<size && a0.
next(); ++i) {
136 if( data.emplace(a0,
static_cast<uint8_t
>(1)).second ) {
140 REQUIRE(i == data.size());
145static void print_mem(
const std::string& pre,
const T& data) {
146 std::size_t bytes_element =
sizeof(
DataType01);
147 std::size_t elements = data.size();
148 std::size_t bytes_net = elements * bytes_element;
149 std::size_t bytes_total = data.get_allocator().memory_usage;
150 double overhead = 0 == bytes_total ? 0.0 : ( 0 == bytes_net ? 10.0 : (double)bytes_total / (double)bytes_net );
151 jau_printf(
"Mem: %s: Elements %'5zu x %zu bytes; %s, %lf ratio\n",
152 pre.c_str(), elements, bytes_element, data.get_allocator().toString(), overhead);
162template<
class T,
typename Size_type>
163static bool test_01_seq_fill_list_itr(
const std::string& type_id,
const Size_type size0,
const Size_type reserve0,
const bool do_print_mem) {
165 REQUIRE(0 == data.get_allocator().memory_usage);
166 REQUIRE(data.size() == 0);
170 data.reserve(reserve0);
171 REQUIRE(data.size() == 0);
172 REQUIRE(0 != data.get_allocator().memory_usage);
173 REQUIRE(data.capacity() == reserve0);
177 REQUIRE(0 != data.get_allocator().memory_usage);
178 REQUIRE(data.size() == size0);
181 REQUIRE(0 != data.get_allocator().memory_usage);
182 REQUIRE(data.size() == size0);
183 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
186 REQUIRE(data.size() == 0);
189 return data.size() == 0;
194 const std::size_t bucket_count = data.bucket_count();
195 std::size_t capacity = 0;
196 for(std::size_t i=0; i<bucket_count; i++) {
197 capacity = data.bucket_size(i);
202static bool test_01_seq_fill_list_hash(
const std::string& type_id,
const std::size_t size0,
const std::size_t reserve0,
const bool do_print_mem) {
205 REQUIRE(0 == data.get_allocator().memory_usage);
206 REQUIRE(data.size() == 0);
210 data.reserve(reserve0);
211 REQUIRE(data.size() == 0);
212 REQUIRE(0 != data.get_allocator().memory_usage);
217 REQUIRE(0 != data.get_allocator().memory_usage);
218 REQUIRE(data.size() == size0);
221 REQUIRE(0 != data.get_allocator().memory_usage);
222 REQUIRE(data.size() == size0);
223 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
226 REQUIRE(data.size() == 0);
229 return data.size() == 0;
232template<
class T,
typename Size_type>
236 REQUIRE(data.size() == 0);
239 data.reserve(reserve0);
240 REQUIRE(data.size() == 0);
241 REQUIRE(data.capacity() == reserve0);
245 REQUIRE(data.size() == size0);
248 REQUIRE(data.size() == size0);
251 REQUIRE(data.size() == 0);
252 return data.size() == 0;
257 typedef std::unordered_set<DataType01, std::hash<DataType01>, std::equal_to<DataType01>, std::allocator<DataType01>> DataType01Set;
259 REQUIRE(data.size() == 0);
262 data.reserve(reserve0);
263 REQUIRE(data.size() == 0);
269 REQUIRE(data.size() == size0);
272 REQUIRE(data.size() == size0);
275 REQUIRE(data.size() == 0);
276 return data.size() == 0;
282template<
class T,
typename Size_type>
286 if( !catch_auto_run ) {
296 if( !catch_auto_run ) {
303template<
class T,
typename Size_type>
305 const bool do_rserv) {
306 if( catch_perf_analysis ) {
307 BENCHMARK(title_pre+
" FillUni_List 1000") {
313 if( catch_auto_run ) {
320 BENCHMARK(title_pre+
" FillUni_List 50") {
323 BENCHMARK(title_pre+
" FillUni_List 100") {
326 BENCHMARK(title_pre+
" FillUni_List 1000") {
333 const bool do_rserv) {
334 if( catch_perf_analysis ) {
335 BENCHMARK(title_pre+
" FillUni_List 1000") {
341 if( catch_auto_run ) {
348 BENCHMARK(title_pre+
" FillUni_List 50") {
351 BENCHMARK(title_pre+
" FillUni_List 100") {
354 BENCHMARK(title_pre+
" FillUni_List 1000") {
362TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
363 if( catch_perf_analysis ) {
376TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
377 if( catch_perf_analysis ) {
#define jau_printf(fmt,...)
const T::value_type * find_const(T &data, typename T::value_type const &elem, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
constexpr UnaryFunction for_each_const(T &data, UnaryFunction f, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
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.
Performance counter std::allocator specialization.
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 bool footprint_fillseq_list_itr(const std::string &type_id, const bool do_rserv)
static Addr48Bit start_addr(start_addr_b)
static bool footprint_fillseq_list_hash(const std::string &type_id, const bool do_rserv)
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 bool test_02_seq_fillunique_find_hash(const std::string &type_id, const std::size_t size0, const std::size_t reserve0)
static bool benchmark_fillunique_find_hash(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
static void test_00_seq_fill(T &data, const Size_type size)
static void test_00_seq_find_hash(T &data)
static bool benchmark_fillunique_find_itr(const std::string &title_pre, const std::string &type_id, const bool do_rserv)
static bool test_01_seq_fill_list_hash(const std::string &type_id, const std::size_t size0, const std::size_t reserve0, const bool do_print_mem)
static bool footprint_fillseq_list_itr(const std::string &type_id, const bool do_rserv)
static const DataType01 * findDataSet01_hash(T &data, DataType01 const &elem) noexcept
static void test_00_seq_fill_unique_hash(T &data, const std::size_t size)
static std::size_t get_capacity(const T &data)
static bool test_01_seq_fill_list_itr(const std::string &type_id, const Size_type size0, const Size_type reserve0, const bool do_print_mem)
static void test_00_seq_find_itr(T &data)
static Addr48Bit start_addr(start_addr_b)
static void test_00_seq_fill_unique_itr(T &data, const Size_type size)
static int test_00_list_itr(T &data)
TEST_CASE("Memory Footprint 01 - Fill Sequential and List", "[datatype][footprint]")