]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/util/performance/assoc/timing/tree_split_join_test.hpp
pb_assoc: Delete.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / util / performance / assoc / timing / tree_split_join_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 tree_split_join_test.hpp
44 * Contains a test for splitting and joining trees
45 */
46
47#ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP
48#define PB_DS_TREE_SPLIT_JOIN_TEST_HPP
49
50#include <performance/time/timing_test_base.hpp>
51#include <performance/io/xml_formatter.hpp>
52#include <common_type/assoc/string_form.hpp>
53#include <iterator>
54
55namespace pb_ds
56{
57
58 namespace test
59 {
60
61 namespace detail
62 {
63
64 template<typename Cntnr, bool Support_Split_Join>
65 class split_join_functor
66 {
67 public:
68 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
69 { }
70
71 void
72 operator()(std::size_t resolution)
73 {
74 for (std::size_t i = 0; i < resolution; ++i)
75 {
76 typename Cntnr::const_iterator mid_it = m_r_container.begin();
77 std::advance(mid_it, m_r_container.size() / 2);
78
79 Cntnr other;
80
81 m_r_container.split(*mid_it, other);
82
83 m_r_container.join(other);
84 }
85 }
86
87 private:
88 Cntnr& m_r_container;
89 };
90
91 template<typename Cntnr>
92 class split_join_functor<
93 Cntnr,
94 false>
95 {
96 public:
97 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
98 { }
99
100 void
101 operator()(std::size_t resolution)
102 {
103 for (std::size_t i = 0; i < resolution; ++i)
104 {
105 typename Cntnr::iterator mid_it = m_r_container.begin();
106 std::advance(mid_it, m_r_container.size() / 2);
107
108 Cntnr other(mid_it, m_r_container.end());
109 m_r_container.erase(mid_it, m_r_container.end());
110
111 m_r_container.insert(other.begin(), other.end());
112 other.clear();
113 }
114 }
115
116 private:
117 Cntnr& m_r_container;
118 };
119
120 } // namespace detail
121
122#define PB_DS_CLASS_T_DEC \
123 template<bool Support_Split_Join>
124
125#define PB_DS_CLASS_C_DEC \
126 tree_split_join_test< \
127 Support_Split_Join>
128
129 template<bool Support_Split_Join>
130 class tree_split_join_test : private pb_ds::test::detail::timing_test_base
131 {
132 public:
133 tree_split_join_test(size_t vn, size_t vs, size_t vm);
134
135 template<typename Cntnr>
136 void
137 operator()(pb_ds::detail::type_to_type<Cntnr>);
138
139 private:
140 tree_split_join_test(const tree_split_join_test& );
141
142 private:
143 const size_t m_vn;
144 const size_t m_vs;
145 const size_t m_vm;
146 };
147
148 PB_DS_CLASS_T_DEC
149 PB_DS_CLASS_C_DEC::
150 tree_split_join_test(size_t vn, size_t vs, size_t vm) :
151 m_vn(vn),
152 m_vs(vs),
153 m_vm(vm)
154 { }
155
156 PB_DS_CLASS_T_DEC
157 template<typename Cntnr>
158 void
159 PB_DS_CLASS_C_DEC::
160 operator()(pb_ds::detail::type_to_type<Cntnr>)
161 {
162 xml_result_set_performance_formatter res_set_fmt(
163 string_form<Cntnr>::name(),
164 string_form<Cntnr>::desc());
165
166 for (size_t v = m_vn; v < m_vm; v += m_vs)
167 {
168 Cntnr cntnr;
169
170 for (size_t ins = 0; ins < v; ++ ins)
171 cntnr.insert((typename Cntnr::value_type)ins);
172
173 pb_ds::test::detail::split_join_functor<Cntnr, Support_Split_Join>
174 fn(cntnr);
175
176 const double res =
177 pb_ds::test::detail::timing_test_base::operator()(fn);
178
179 res_set_fmt.add_res(v, res);
180 }
181 }
182
183#undef PB_DS_CLASS_T_DEC
184
185#undef PB_DS_CLASS_C_DEC
186
187 } // namespace test
188
189} // namespace pb_ds
190
191#endif // #ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP
192