21 #define BOOST_TEST_MODULE libjmmcg_tests
22 #include <boost/test/included/unit_test.hpp>
24 #include <boost/mpl/list.hpp>
26 #include "core/ave_deviation_meter.hpp"
27 #include "core/stats_output.hpp"
28 #include "core/thread_wrapper.hpp"
29 #include "core/unique_ptr.hpp"
31 #include <boost/move/unique_ptr.hpp>
35 using namespace libjmmcg;
40 using lock_traits=api_lock_traits<platform_api, Mdl>;
41 using element_type=
int;
46 obj(element_type i)
noexcept(
true) :
init(i) {}
47 ~
obj()
noexcept(
true) {}
50 deleter_t().operator()(
this);
54 using ptr_types=boost::mpl::list<
55 std::unique_ptr<obj<heavyweight_threading>>,
56 boost::movelib::unique_ptr<obj<heavyweight_threading>>,
57 unique_ptr<obj<sequential_mode>, api_lock_traits<platform_api, sequential_mode>>,
58 unique_ptr<obj<heavyweight_threading>, api_lock_traits<platform_api, heavyweight_threading>>
62 template<
class Element>
63 struct cctor_thread
final :
public ppd::wrapper<ppd::platform_api, heavyweight_threading> {
72 return typename cont_t::value_type(
new typename cont_t::value_type::element_type(++i));
83 while (!
cont.empty()) {
84 const typename cont_t::value_type tmp(std::move(cont.back()));
91 template<
class Element>
92 struct dtor_thread
final :
public ppd::wrapper<ppd::platform_api, heavyweight_threading> {
101 return typename cont_t::value_type(
new typename cont_t::value_type::element_type(++i));
112 while (!
cont.empty()) {
120 BOOST_AUTO_TEST_SUITE(performance_cctor, *stats_to_csv::make_fixture(
"unique_ptr_parallel_cctor.csv"))
122 BOOST_AUTO_TEST_SUITE(unique_ptr_parallel_tests)
129 BOOST_AUTO_TEST_CASE_TEMPLATE(parallel_cctor, ptr_t, ptr_types) {
130 typedef cctor_thread<ptr_t> thread_t;
131 #ifdef JMMCG_PERFORMANCE_TESTS
132 const std::size_t num_items=100000000;
134 const std::size_t num_items=100;
136 const unsigned short loops_for_conv=50;
137 const double perc_conv_estimate=5.0;
139 const std::pair<timed_results_t,
bool> timed_results(compute_average_deviation<timed_results_t::value_type>(
143 typename thread_t::cont_t c;
144 std::generate_n(std::back_inserter(c), num_items,
typename thread_t::make());
148 const auto t1=std::chrono::high_resolution_clock::now();
149 th1.create_running();
150 th2.create_running();
152 api_threading_traits<platform_api, heavyweight_threading>::sleep(100);
153 }
while (th1.is_running() || th2.is_running());
154 const auto t2=std::chrono::high_resolution_clock::now();
155 BOOST_CHECK(th1.cont.empty());
156 BOOST_CHECK(th2.cont.empty());
157 BOOST_CHECK(c.empty());
158 return timed_results_t::value_type(num_items/(
static_cast<
double>(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count())/1000000));
161 std::cout<<thread_t::thread_traits::demangle_name(
typeid(ptr_t))<<
" rate cctors/sec="<<timed_results.first<<std::endl;
162 #ifdef JMMCG_PERFORMANCE_TESTS
163 stats_to_csv::handle->stats<<timed_results.first.to_csv()<<std::flush;
164 BOOST_CHECK(!timed_results.second);
168 BOOST_AUTO_TEST_SUITE_END()
170 BOOST_AUTO_TEST_SUITE(performance_cctor, *stats_to_csv::make_fixture(
"unique_ptr_parallel_dtor.csv"))
177 BOOST_AUTO_TEST_CASE_TEMPLATE(parallel_deletes, ptr_t, ptr_types) {
178 typedef dtor_thread<ptr_t> thread_t;
179 #ifdef JMMCG_PERFORMANCE_TESTS
180 const std::size_t num_items=100000000;
182 const std::size_t num_items=100;
184 const unsigned short loops_for_conv=50;
185 const double perc_conv_estimate=5.0;
187 const std::pair<timed_results_t,
bool> timed_results(compute_average_deviation<timed_results_t::value_type>(
191 typename thread_t::cont_t c;
192 std::generate_n(std::back_inserter(c), num_items,
typename thread_t::make());
196 const auto t1=std::chrono::high_resolution_clock::now();
197 th1.create_running();
198 th2.create_running();
200 api_threading_traits<platform_api, heavyweight_threading>::sleep(100);
201 }
while (th1.is_running() || th2.is_running());
202 const auto t2=std::chrono::high_resolution_clock::now();
203 BOOST_CHECK(th1.cont.empty());
204 BOOST_CHECK(th2.cont.empty());
205 BOOST_CHECK(c.empty());
206 return timed_results_t::value_type(num_items/(
static_cast<
double>(std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count())/1000000));
209 std::cout<<thread_t::thread_traits::demangle_name(
typeid(ptr_t))<<
" rate dtors/sec="<<timed_results.first<<std::endl;
210 #ifdef JMMCG_PERFORMANCE_TESTS
211 stats_to_csv::handle->stats<<timed_results.first.to_csv()<<std::flush;
212 BOOST_CHECK(!timed_results.second);
216 BOOST_AUTO_TEST_SUITE_END()
218 BOOST_AUTO_TEST_SUITE_END()