diff --git a/test/test_circ_elem_array.cpp b/test/test_circ_elem_array.cpp index 27d29d3..5fbceb0 100644 --- a/test/test_circ_elem_array.cpp +++ b/test/test_circ_elem_array.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "circ_elem_array.h" #include "test.h" @@ -19,7 +20,7 @@ private slots: void test_inst(void); void test_prod_cons_1v1(void); void test_prod_cons_1v3(void); - void test_prod_cons_1v8(void); + void test_prod_cons_performance(void); } unit__; #include "test_circ_elem_array.moc" @@ -46,7 +47,7 @@ void Unit::test_inst(void) { static_cast(cq_t::elem_size)); } -template +template void test_prod_cons(void) { ::new (cq__) cq_t; std::thread producers[N]; @@ -60,6 +61,10 @@ void test_prod_cons(void) { }; std::unordered_map> list[std::extent::value]; + auto push_data = Confirmation ? [](std::vector& l, int dat) { + l.push_back(dat); + } : [](std::vector&, int) {}; + int cid = 0; for (auto& t : consumers) { t = std::thread{[&, cid] { @@ -76,25 +81,25 @@ void test_prod_cons(void) { cq__->put(pmsg); if (msg.pid_ < 0) goto finished; ++cur; - list[cid][msg.pid_].push_back(msg.dat_); + push_data(list[cid][msg.pid_], msg.dat_); } std::this_thread::yield(); } while(1); finished: - if (++fini == std::extent::value) { - auto ts = sw.elapsed(); - std::cout << "[" << N << ":" << M << ", " << Loops << "]" << std::endl - << "performance: " << (double(ts) / double(Loops * N)) << " us/d" << std::endl; - std::cout << "confirming..." << std::endl; - for (auto& cons_vec : list) { - for (int n = 0; n < static_cast(std::extent::value); ++n) { - auto& vec = cons_vec[n]; - QCOMPARE(vec.size(), static_cast(Loops)); - int i = 0; - for (int d : vec) { - QCOMPARE(i, d); - ++i; - } + if (++fini != std::extent::value) return; + auto ts = sw.elapsed(); + std::cout << "[" << N << ":" << M << ", " << Loops << "]" << std::endl + << "performance: " << (double(ts) / double(Loops * N)) << " us/d" << std::endl; + if (!Confirmation) return; + std::cout << "confirming..." << std::endl; + for (auto& cons_vec : list) { + for (int n = 0; n < static_cast(std::extent::value); ++n) { + auto& vec = cons_vec[n]; + QCOMPARE(vec.size(), static_cast(Loops)); + int i = 0; + for (int d : vec) { + QCOMPARE(i, d); + ++i; } } } @@ -140,8 +145,23 @@ void Unit::test_prod_cons_1v3(void) { test_prod_cons<1, 3>(); } -void Unit::test_prod_cons_1v8(void) { - test_prod_cons<1, 8>(); +template +struct test_performance { + static void start(void) { + test_prod_cons<1, B, false>(); + test_performance::start(); + } +}; + +template +struct test_performance { + static void start(void) { + test_prod_cons<1, E, false>(); + } +}; + +void Unit::test_prod_cons_performance(void) { + test_performance<1, 10>::start(); } } // internal-linkage