]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_pop_test.hpp
typelist_assoc_container.hpp: Remove, unused.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / performance / priority_queue / timing / push_pop_test.hpp
CommitLineData
4569a895
AT
1// -*- C++ -*-
2
3// Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4//
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 2, or (at your option) any later
9// version.
10
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.
15
16// You should have received a copy of the GNU General Public License
17// along with this library; see the file COPYING. If not, write to
18// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19// MA 02111-1307, USA.
20
21// As a special exception, you may use this file as part of a free
22// software library without restriction. Specifically, if other files
23// instantiate templates or use macros or inline functions from this
24// file, or you compile this file and link it with other files to
25// produce an executable, this file does not by itself cause the
26// resulting executable to be covered by the GNU General Public
27// License. This exception does not however invalidate any other
28// reasons why the executable file might be covered by the GNU General
29// Public License.
30
31// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
33// Permission to use, copy, modify, sell, and distribute this software
34// is hereby granted without fee, provided that the above copyright
35// notice appears in all copies, and that both that copyright notice
36// and this permission notice appear in supporting documentation. None
37// of the above authors, nor IBM Haifa Research Laboratories, make any
38// representation about the suitability of this software for any
39// purpose. It is provided "as is" without express or implied
40// warranty.
41
42/**
43 * @file push_pop_test.hpp
44 * Contains a push performance test.
45 */
46
47#ifndef PB_DS_PUSH_TEST_HPP
48#define PB_DS_PUSH_TEST_HPP
49
50#include <performance/time/timing_test_base.hpp>
51#include <ext/pb_ds/detail/type_utils.hpp>
52#include <performance/io/xml_formatter.hpp>
53#include <common_type/priority_queue/string_form.hpp>
54#include <iterator>
55
56namespace pb_ds
57{
58
59 namespace test
60 {
61
62 namespace detail
63 {
64
65 template<typename It, class Cntnr>
66 class push_pop_push_pop_functor
67 {
68 public:
69 push_pop_push_pop_functor(It ins_it_b, It ins_it_e) : m_ins_it_b(ins_it_b),
70 m_ins_it_e(ins_it_e)
71 { }
72
73 void
74 operator()(std::size_t resolution)
75 {
76 for (std::size_t i = 0; i < resolution; ++i)
77 {
78 Cntnr cntnr;
79
80 for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
81 cntnr.push((typename Cntnr::const_reference)(ins_it->first));
82
83 while (!cntnr.empty())
84 cntnr.pop();
85 }
86 }
87
88 private:
89 const It m_ins_it_b;
90 const It m_ins_it_e;
91 };
92
93 } // namespace detail
94
95#define PB_DS_CLASS_T_DEC \
96 template<typename It>
97
98#define PB_DS_CLASS_C_DEC \
99 push_pop_test< \
100 It>
101
102 template<typename It>
103 class push_pop_test : private pb_ds::test::detail::timing_test_base
104 {
105 public:
106 push_pop_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm);
107
108 template<typename Cntnr>
109 void
d7f245b1 110 operator()(__gnu_cxx::typelist::detail::type_to_type<Cntnr>);
4569a895
AT
111
112 private:
113 push_pop_test(const push_pop_test& );
114
115 template<typename Cntnr>
116 void
d7f245b1 117 push(__gnu_cxx::typelist::detail::type_to_type<Cntnr>, It ins_it_b, It ins_it_e);
4569a895
AT
118
119 private:
120 const It m_ins_b;
121
122 const size_t m_ins_vn;
123 const size_t m_ins_vs;
124 const size_t m_ins_vm;
125 };
126
127 PB_DS_CLASS_T_DEC
128 PB_DS_CLASS_C_DEC::
129 push_pop_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm) :
130 m_ins_b(ins_b),
131 m_ins_vn(ins_vn),
132 m_ins_vs(ins_vs),
133 m_ins_vm(ins_vm)
134 { }
135
136 PB_DS_CLASS_T_DEC
137 template<typename Cntnr>
138 void
139 PB_DS_CLASS_C_DEC::
d7f245b1 140 operator()(__gnu_cxx::typelist::detail::type_to_type<Cntnr>)
4569a895
AT
141 {
142 xml_result_set_performance_formatter res_set_fmt(
143 string_form<Cntnr>::name(),
144 string_form<Cntnr>::desc());
145
146 for (size_t size_i = 0; m_ins_vn + size_i* m_ins_vs < m_ins_vm; ++size_i)
147 {
148 const size_t v = m_ins_vn + size_i* m_ins_vs;
149
150 It ins_it_b = m_ins_b;
151 It ins_it_e = m_ins_b;
152 std::advance(ins_it_e, v);
153
154 pb_ds::test::detail::push_pop_push_pop_functor<It, Cntnr>
155 fn(ins_it_b, ins_it_e);
156
157 const double res =
158 pb_ds::test::detail::timing_test_base::operator()(fn);
159
160 res_set_fmt.add_res(v, res / v);
161 }
162 }
163
164 PB_DS_CLASS_T_DEC
165 template<typename Cntnr>
166 void
167 PB_DS_CLASS_C_DEC::
d7f245b1 168 push(__gnu_cxx::typelist::detail::type_to_type<Cntnr>, It ins_it_b, It ins_it_e)
4569a895
AT
169 {
170 Cntnr cntnr;
171
172 for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
173 cntnr.push((typename Cntnr::const_reference)(*ins_it));
174 }
175
176#undef PB_DS_CLASS_T_DEC
177
178#undef PB_DS_CLASS_C_DEC
179
180 } // namespace test
181
182} // namespace pb_ds
183
184#endif // #ifndef PB_DS_PUSH_TEST_HPP
185