29#include <unordered_set>
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) {
76 const DataType01 *found = jau::find_const<T>(data, elem);
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) {
120 const DataType01* exist = jau::find_const<T>(data, elem);
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 printf(
"Mem: %s: Elements %s x %zu bytes; %s, %lf ratio\n",
153 bytes_element, data.get_allocator().toString(10, 5).c_str(), overhead);
163template<
class T,
typename Size_type>
164static 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) {
166 REQUIRE(0 == data.get_allocator().memory_usage);
167 REQUIRE(data.size() == 0);
171 data.reserve(reserve0);
172 REQUIRE(data.size() == 0);
173 REQUIRE(0 != data.get_allocator().memory_usage);
174 REQUIRE(data.capacity() == reserve0);
177 test_00_seq_fill<T, Size_type>(data, size0);
178 REQUIRE(0 != data.get_allocator().memory_usage);
179 REQUIRE(data.size() == size0);
181 test_00_list_itr<T>(data);
182 REQUIRE(0 != data.get_allocator().memory_usage);
183 REQUIRE(data.size() == size0);
184 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
187 REQUIRE(data.size() == 0);
190 return data.size() == 0;
195 const std::size_t bucket_count = data.bucket_count();
196 std::size_t capacity = 0;
197 for(std::size_t i=0; i<bucket_count; i++) {
198 capacity = data.bucket_size(i);
203static 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) {
206 REQUIRE(0 == data.get_allocator().memory_usage);
207 REQUIRE(data.size() == 0);
211 data.reserve(reserve0);
212 REQUIRE(data.size() == 0);
213 REQUIRE(0 != data.get_allocator().memory_usage);
214 REQUIRE(get_capacity<DataType01Set>(data) >= reserve0);
218 REQUIRE(0 != data.get_allocator().memory_usage);
219 REQUIRE(data.size() == size0);
221 test_00_list_itr<DataType01Set>(data);
222 REQUIRE(0 != data.get_allocator().memory_usage);
223 REQUIRE(data.size() == size0);
224 if( do_print_mem ) {
print_mem(type_id+
" 01 (full_)", data); }
227 REQUIRE(data.size() == 0);
230 return data.size() == 0;
233template<
class T,
typename Size_type>
237 REQUIRE(data.size() == 0);
240 data.reserve(reserve0);
241 REQUIRE(data.size() == 0);
242 REQUIRE(data.capacity() == reserve0);
245 test_00_seq_fill_unique_itr<T, Size_type>(data, size0);
246 REQUIRE(data.size() == size0);
248 test_00_seq_find_itr<T, Size_type>(data);
249 REQUIRE(data.size() == size0);
252 REQUIRE(data.size() == 0);
253 return data.size() == 0;
258 typedef std::unordered_set<DataType01, std::hash<DataType01>, std::equal_to<DataType01>, std::allocator<DataType01>> DataType01Set;
260 REQUIRE(data.size() == 0);
263 data.reserve(reserve0);
264 REQUIRE(data.size() == 0);
270 REQUIRE(data.size() == size0);
273 REQUIRE(data.size() == size0);
276 REQUIRE(data.size() == 0);
277 return data.size() == 0;
283template<
class T,
typename Size_type>
286 test_01_seq_fill_list_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0,
true);
288 test_01_seq_fill_list_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0,
true);
289 test_01_seq_fill_list_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0,
true);
304template<
class T,
typename Size_type>
306 const bool do_rserv) {
308 BENCHMARK(title_pre+
" FillUni_List 1000") {
309 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
315 test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
321 BENCHMARK(title_pre+
" FillUni_List 50") {
322 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 50, do_rserv? 50 : 0);
324 BENCHMARK(title_pre+
" FillUni_List 100") {
325 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 100, do_rserv? 100 : 0);
327 BENCHMARK(title_pre+
" FillUni_List 1000") {
328 return test_02_seq_fillunique_find_itr<T, Size_type>(type_id, 1000, do_rserv? 1000 : 0);
334 const bool do_rserv) {
336 BENCHMARK(title_pre+
" FillUni_List 1000") {
349 BENCHMARK(title_pre+
" FillUni_List 50") {
352 BENCHMARK(title_pre+
" FillUni_List 100") {
355 BENCHMARK(title_pre+
" FillUni_List 1000") {
363TEST_CASE(
"Memory Footprint 01 - Fill Sequential and List",
"[datatype][footprint]" ) {
366 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_empty_",
false);
367 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>,
jau::nsize_t>(
"cowdarray_empty_",
false);
371 footprint_fillseq_list_itr< std::vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"stdvec_empty_",
false);
372 footprint_fillseq_list_itr< jau::darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>,
jau::nsize_t>(
"darray_empty_",
false);
373 footprint_fillseq_list_itr< jau::cow_vector<DataType01, counting_allocator<DataType01>>, std::size_t>(
"cowstdvec_empty_",
false);
374 footprint_fillseq_list_itr< jau::cow_darray<DataType01, jau::nsize_t, counting_callocator<DataType01>>,
jau::nsize_t>(
"cowdarray_empty_",
false);
377TEST_CASE(
"Perf Test 02 - Fill Unique and List, empty and reserve",
"[datatype][unique]" ) {
380 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_empty_itr",
"cowstdvec_empty_",
false);
381 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>,
jau::nsize_t>(
"COW_DArray_empty_itr",
"cowdarray_empty_",
false);
386 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_empty_itr",
"stdvec_empty_",
false);
387 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>,
jau::nsize_t>(
"JAU_DArray_empty_itr",
"darray_empty_",
false);
388 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_empty_itr",
"cowstdvec_empty_",
false);
389 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>,
jau::nsize_t>(
"COW_DArray_empty_itr",
"cowdarray_empty_",
false);
392 benchmark_fillunique_find_itr< std::vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"STD_Vector_rserv_itr",
"stdvec_rserv",
true);
393 benchmark_fillunique_find_itr< jau::darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>,
jau::nsize_t>(
"JAU_DArray_rserv_itr",
"darray_rserv",
true);
394 benchmark_fillunique_find_itr< jau::cow_vector<DataType01, std::allocator<DataType01>>, std::size_t>(
"COW_Vector_rserv_itr",
"cowstdvec_rserv",
true);
395 benchmark_fillunique_find_itr< jau::cow_darray<DataType01, jau::nsize_t, jau::callocator<DataType01>>,
jau::nsize_t>(
"COW_DArray_rserv_itr",
"cowdarray_rserv",
true);
bool catch_perf_analysis
Run w/ command-line arg '–perf_analysis'.
bool catch_auto_run
Run w/o command-line args, i.e.
constexpr UnaryFunction for_each_const(T &data, UnaryFunction f, std::enable_if_t< is_cow_type< T >::value, bool >=true) noexcept
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.
Performance counter std::allocator specialization.
const DataType01 * findDataSet01_hash(T &data, DataType01 const &elem) noexcept
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 uint8_t start_addr_b[]
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 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]")
int printf(const char *format,...)
Operating Systems predefined macros.