3 // Copyright (C) 2005-2018 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
34 * Contains a join performance test.
37 #ifndef PB_DS_JOIN_TEST_HPP
38 #define PB_DS_JOIN_TEST_HPP
40 #include <performance/time/timing_test_base.hpp>
41 #include <ext/pb_ds/detail/type_utils.hpp>
42 #include <performance/io/xml_formatter.hpp>
43 #include <common_type/priority_queue/string_form.hpp>
52 template<typename It, typename Cntnr>
53 class double_push_functor
59 double_push_functor(It b, It e) : _M_begin(b), _M_end(e) { }
62 operator()(std::size_t resolution)
64 typedef typename Cntnr::const_reference const_reference;
65 for (std::size_t n = 0; n < resolution; ++n)
69 for (It it = _M_begin; it != _M_end; ++it)
71 c0.push(const_reference(it->first));
72 c1.push(const_reference(it->first));
78 template<typename It, typename Cntnr>
79 class double_push_join_functor
85 double_push_join_functor(It b, It e) : _M_begin(b), _M_end(e) { }
88 operator()(std::size_t resolution)
90 typedef typename Cntnr::const_reference const_reference;
91 for (std::size_t n = 0; n < resolution; ++n)
95 for (It it = _M_begin; it != _M_end; ++it)
97 c0.push(const_reference(it->first));
98 c1.push(const_reference(it->first));
104 } // namespace detail
106 template<typename It>
107 class join_test : private __gnu_pbds::test::detail::timing_test_base
110 join_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm)
111 : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(ins_vs), m_ins_vm(ins_vm)
114 template<typename Cntnr>
118 using __gnu_pbds::test::detail::double_push_functor;
119 using __gnu_pbds::test::detail::double_push_join_functor;
120 typedef __gnu_pbds::test::detail::timing_test_base base_type;
121 typedef double_push_functor<It, Cntnr> psh_fnct;
122 typedef double_push_join_functor<It, Cntnr> psh_jn_fnct;
124 typedef xml_result_set_performance_formatter formatter_type;
125 formatter_type res(string_form<Cntnr>::name(),
126 string_form<Cntnr>::desc());
128 for (size_t n = 0; m_ins_vn + n* m_ins_vs < m_ins_vm; ++n)
130 const size_t v = m_ins_vn + n * m_ins_vs;
135 psh_fnct double_push_fn(b, e);
136 const double dbl_psh_res = base_type::operator()(double_push_fn);
137 psh_jn_fnct dbl_psh_jn_fn(b, e);
138 const double dbl_psh_jn_res = base_type::operator()(dbl_psh_jn_fn);
139 const double min_res = double(timing_test_base::min_time_res());
140 const double effective_delta = std::max(dbl_psh_jn_res - dbl_psh_res, min_res);
141 res.add_res(v, effective_delta / v);
146 join_test(const join_test&);
148 template<typename Cntnr>
150 join(Cntnr, It b, It e)
153 typedef typename Cntnr::const_reference const_reference;
154 for (It it = b; it != e; ++it)
155 cntnr.join(const_reference(*it));
159 const size_t m_ins_vn;
160 const size_t m_ins_vs;
161 const size_t m_ins_vm;
164 } // namespace __gnu_pbds