Merged with mainline at revision 128810.
[official-gcc.git] / libstdc++-v3 / testsuite / util / performance / assoc / timing / tree_split_join_test.hpp
blob7595dc2cb0d9b0f304b9687e3f518710cb13ce20
1 // -*- C++ -*-
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.
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 COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
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.
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
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.
42 /**
43 * @file tree_split_join_test.hpp
44 * Contains a test for splitting and joining trees
47 #ifndef PB_DS_TREE_SPLIT_JOIN_TEST_HPP
48 #define PB_DS_TREE_SPLIT_JOIN_TEST_HPP
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>
55 namespace __gnu_pbds
57 namespace test
59 namespace detail
61 template<typename Cntnr, bool Support_Split_Join>
62 class split_join_functor
64 public:
65 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
66 { }
68 void
69 operator()(std::size_t resolution)
71 for (std::size_t i = 0; i < resolution; ++i)
73 typename Cntnr::const_iterator mid_it = m_r_container.begin();
74 std::advance(mid_it, m_r_container.size() / 2);
75 Cntnr other;
76 m_r_container.split(*mid_it, other);
77 m_r_container.join(other);
81 private:
82 Cntnr& m_r_container;
85 template<typename Cntnr>
86 class split_join_functor<Cntnr, false>
88 public:
89 split_join_functor(Cntnr& r_container) : m_r_container(r_container)
90 { }
92 void
93 operator()(std::size_t resolution)
95 for (std::size_t i = 0; i < resolution; ++i)
97 typename Cntnr::iterator mid_it = m_r_container.begin();
98 std::advance(mid_it, m_r_container.size() / 2);
100 Cntnr other(mid_it, m_r_container.end());
101 m_r_container.erase(mid_it, m_r_container.end());
103 m_r_container.insert(other.begin(), other.end());
104 other.clear();
108 private:
109 Cntnr& m_r_container;
111 } // namespace detail
113 template<bool Support_Split_Join>
114 class tree_split_join_test : private __gnu_pbds::test::detail::timing_test_base
116 public:
117 tree_split_join_test(size_t vn, size_t vs, size_t vm);
119 template<typename Cntnr>
120 void
121 operator()(Cntnr);
123 private:
124 tree_split_join_test(const tree_split_join_test& );
126 private:
127 const size_t m_vn;
128 const size_t m_vs;
129 const size_t m_vm;
132 template<bool Support_Split_Join>
133 tree_split_join_test<Support_Split_Join>::
134 tree_split_join_test(size_t vn, size_t vs, size_t vm) :
135 m_vn(vn),
136 m_vs(vs),
137 m_vm(vm)
140 template<bool Support_Split_Join>
141 template<typename Cntnr>
142 void
143 tree_split_join_test<Support_Split_Join>::
144 operator()(Cntnr)
146 typedef xml_result_set_performance_formatter formatter_type;
147 formatter_type res_set_fmt(string_form<Cntnr>::name(),
148 string_form<Cntnr>::desc());
150 for (size_t v = m_vn; v < m_vm; v += m_vs)
152 Cntnr cntnr;
153 for (size_t ins = 0; ins < v; ++ ins)
154 cntnr.insert((typename Cntnr::value_type)ins);
156 __gnu_pbds::test::detail::split_join_functor<Cntnr, Support_Split_Join>
157 fn(cntnr);
159 const double res =
160 __gnu_pbds::test::detail::timing_test_base::operator()(fn);
161 res_set_fmt.add_res(v, res);
164 } // namespace test
165 } // namespace __gnu_pbds
167 #endif