summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/util/performance/priority_queue
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libstdc++-v3/testsuite/util/performance/priority_queue
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libstdc++-v3/testsuite/util/performance/priority_queue')
-rw-r--r--libstdc++-v3/testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp111
-rw-r--r--libstdc++-v3/testsuite/util/performance/priority_queue/timing/join_test.hpp167
-rw-r--r--libstdc++-v3/testsuite/util/performance/priority_queue/timing/modify_test.hpp329
-rw-r--r--libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_pop_test.hpp141
-rw-r--r--libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_test.hpp144
5 files changed, 892 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp b/libstdc++-v3/testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp
new file mode 100644
index 000000000..3a98813df
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/performance/priority_queue/mem_usage/pop_test.hpp
@@ -0,0 +1,111 @@
+// -*- C++ -*-
+
+// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
+
+// Permission to use, copy, modify, sell, and distribute this software
+// is hereby granted without fee, provided that the above copyright
+// notice appears in all copies, and that both that copyright notice
+// and this permission notice appear in supporting documentation. None
+// of the above authors, nor IBM Haifa Research Laboratories, make any
+// representation about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+
+/**
+ * @file pop_test.hpp
+ * Contains a generic pop test.
+ */
+
+#ifndef PB_DS_POP_TEST_HPP
+#define PB_DS_POP_TEST_HPP
+
+#include <iterator>
+#include <testsuite_allocator.h>
+#include <ext/pb_ds/detail/type_utils.hpp>
+#include <performance/io/xml_formatter.hpp>
+#include <common_type/priority_queue/string_form.hpp>
+
+namespace __gnu_pbds
+{
+ namespace test
+ {
+ template<typename It>
+ class pop_test
+ {
+ public:
+ pop_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm)
+ : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(ins_vs), m_ins_vm(ins_vm)
+ { }
+
+ template<typename Cntnr>
+ void
+ operator()(Cntnr);
+
+ private:
+ pop_test(const pop_test&);
+
+ const It m_ins_b;
+ const size_t m_ins_vn;
+ const size_t m_ins_vs;
+ const size_t m_ins_vm;
+ };
+
+ template<typename It>
+ template<typename Cntnr>
+ void
+ pop_test<It>::
+ operator()(Cntnr)
+ {
+ typedef xml_result_set_performance_formatter formatter_type;
+ formatter_type res_set_fmt(string_form<Cntnr>::name(),
+ string_form<Cntnr>::desc());
+
+ for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i)
+ {
+ const size_t ins_size = m_ins_vn + i * m_ins_vs;
+ It ins_it_b = m_ins_b;
+ It ins_it_e = m_ins_b;
+ std::advance(ins_it_e, ins_size);
+
+ typedef __gnu_test::tracker_allocator_counter counter_type;
+ __gnu_test::tracker_allocator<char> alloc;
+
+ const size_t init_mem = counter_type::get_allocation_count()
+ - counter_type::get_deallocation_count();
+ Cntnr cntnr;
+ for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
+ cntnr.push(ins_it->first);
+
+ while (cntnr.size() > 1)
+ cntnr.pop();
+
+ const size_t final_mem = counter_type::get_allocation_count()
+ - counter_type::get_deallocation_count();
+ assert(final_mem > init_mem);
+ const size_t delta_mem = final_mem - init_mem;
+ res_set_fmt.add_res(ins_size, static_cast<double>(delta_mem));
+ }
+ }
+ } // namespace test
+} // namespace __gnu_pbds
+
+#endif
+
diff --git a/libstdc++-v3/testsuite/util/performance/priority_queue/timing/join_test.hpp b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/join_test.hpp
new file mode 100644
index 000000000..1281f40c3
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/join_test.hpp
@@ -0,0 +1,167 @@
+// -*- C++ -*-
+
+// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
+
+// Permission to use, copy, modify, sell, and distribute this software
+// is hereby granted without fee, provided that the above copyright
+// notice appears in all copies, and that both that copyright notice
+// and this permission notice appear in supporting documentation. None
+// of the above authors, nor IBM Haifa Research Laboratories, make any
+// representation about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+
+/**
+ * @file join_test.hpp
+ * Contains a join performance test.
+ */
+
+#ifndef PB_DS_JOIN_TEST_HPP
+#define PB_DS_JOIN_TEST_HPP
+
+#include <performance/time/timing_test_base.hpp>
+#include <ext/pb_ds/detail/type_utils.hpp>
+#include <performance/io/xml_formatter.hpp>
+#include <common_type/priority_queue/string_form.hpp>
+#include <iterator>
+
+namespace __gnu_pbds
+{
+ namespace test
+ {
+ namespace detail
+ {
+ template<typename It, typename Cntnr>
+ class double_push_functor
+ {
+ const It _M_begin;
+ const It _M_end;
+
+ public:
+ double_push_functor(It b, It e) : _M_begin(b), _M_end(e) { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ typedef typename Cntnr::const_reference const_reference;
+ for (std::size_t n = 0; n < resolution; ++n)
+ {
+ Cntnr c0;
+ Cntnr c1;
+ for (It it = _M_begin; it != _M_end; ++it)
+ {
+ c0.push(const_reference(it->first));
+ c1.push(const_reference(it->first));
+ }
+ }
+ }
+ };
+
+ template<typename It, typename Cntnr>
+ class double_push_join_functor
+ {
+ const It _M_begin;
+ const It _M_end;
+
+ public:
+ double_push_join_functor(It b, It e) : _M_begin(b), _M_end(e) { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ typedef typename Cntnr::const_reference const_reference;
+ for (std::size_t n = 0; n < resolution; ++n)
+ {
+ Cntnr c0;
+ Cntnr c1;
+ for (It it = _M_begin; it != _M_end; ++it)
+ {
+ c0.push(const_reference(it->first));
+ c1.push(const_reference(it->first));
+ }
+ c0.join(c1);
+ }
+ }
+ };
+ } // namespace detail
+
+ template<typename It>
+ class join_test : private __gnu_pbds::test::detail::timing_test_base
+ {
+ public:
+ join_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm)
+ : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(ins_vs), m_ins_vm(ins_vm)
+ { }
+
+ template<typename Cntnr>
+ void
+ operator()(Cntnr)
+ {
+ using __gnu_pbds::test::detail::double_push_functor;
+ using __gnu_pbds::test::detail::double_push_join_functor;
+ typedef __gnu_pbds::test::detail::timing_test_base base_type;
+ typedef double_push_functor<It, Cntnr> psh_fnct;
+ typedef double_push_join_functor<It, Cntnr> psh_jn_fnct;
+
+ typedef xml_result_set_performance_formatter formatter_type;
+ formatter_type res(string_form<Cntnr>::name(),
+ string_form<Cntnr>::desc());
+
+ for (size_t n = 0; m_ins_vn + n* m_ins_vs < m_ins_vm; ++n)
+ {
+ const size_t v = m_ins_vn + n * m_ins_vs;
+ It b = m_ins_b;
+ It e = m_ins_b;
+ std::advance(e, v);
+
+ psh_fnct double_push_fn(b, e);
+ const double dbl_psh_res = base_type::operator()(double_push_fn);
+ psh_jn_fnct dbl_psh_jn_fn(b, e);
+ const double dbl_psh_jn_res = base_type::operator()(dbl_psh_jn_fn);
+ const double min_res = double(timing_test_base::min_time_res());
+ const double effective_delta = std::max(dbl_psh_jn_res - dbl_psh_res, min_res);
+ res.add_res(v, effective_delta / v);
+ }
+ }
+
+ private:
+ join_test(const join_test&);
+
+ template<typename Cntnr>
+ void
+ join(Cntnr, It b, It e)
+ {
+ Cntnr cntnr;
+ typedef typename Cntnr::const_reference const_reference;
+ for (It it = b; it != e; ++it)
+ cntnr.join(const_reference(*it));
+ }
+
+ const It m_ins_b;
+ const size_t m_ins_vn;
+ const size_t m_ins_vs;
+ const size_t m_ins_vm;
+ };
+ } // namespace test
+} // namespace __gnu_pbds
+
+#endif
+
diff --git a/libstdc++-v3/testsuite/util/performance/priority_queue/timing/modify_test.hpp b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/modify_test.hpp
new file mode 100644
index 000000000..01e082058
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/modify_test.hpp
@@ -0,0 +1,329 @@
+// -*- C++ -*-
+
+// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
+
+// Permission to use, copy, modify, sell, and distribute this software
+// is hereby granted without fee, provided that the above copyright
+// notice appears in all copies, and that both that copyright notice
+// and this permission notice appear in supporting documentation. None
+// of the above authors, nor IBM Haifa Research Laboratories, make any
+// representation about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+
+/**
+ * @file modify_test.hpp
+ * Contains a modify performance test.
+ */
+
+#ifndef PB_DS_JOIN_TEST_HPP
+#define PB_DS_JOIN_TEST_HPP
+
+#include <performance/time/timing_test_base.hpp>
+#include <ext/pb_ds/detail/type_utils.hpp>
+#include <performance/io/xml_formatter.hpp>
+#include <common_type/priority_queue/string_form.hpp>
+#include <iterator>
+
+namespace __gnu_pbds
+{
+ namespace test
+ {
+ namespace detail
+ {
+ // Primary templates.
+ template<typename It, class Cntnr, class Tag>
+ class push_functor
+ {
+ public:
+ push_functor(It ins_it_b, It ins_it_e)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ typedef typename Cntnr::point_iterator point_iterator;
+ typedef typename Cntnr::const_reference const_reference;
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+ typedef std::vector<point_iterator> it_vec_t;
+ it_vec_t m_a_its;
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ m_a_its.push_back(c.push(const_reference(ins_it->first)));
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ };
+
+ template<typename It, class Cntnr, class Tag>
+ class push_modify_functor
+ {
+ private:
+ typedef typename Cntnr::point_iterator point_iterator;
+ typedef typename Cntnr::const_reference const_reference;
+ typedef typename Cntnr::value_type value_type;
+
+ public:
+ push_modify_functor(It ins_it_b, It ins_it_e, value_type mod_val)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e), m_mod_val(mod_val)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+ typedef std::vector<typename Cntnr::point_iterator> it_vec_t;
+ it_vec_t m_a_its;
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ m_a_its.push_back(c.push(const_reference(ins_it->first)));
+
+ typename it_vec_t::iterator mod_it = m_a_its.begin();
+ while (mod_it != m_a_its.end())
+ c.modify(*mod_it++, m_mod_val);
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ const value_type m_mod_val;
+ };
+
+ // Specializations.
+ template<typename It, class Cntnr>
+ class push_functor<It, Cntnr, __gnu_pbds::binary_heap_tag>
+ {
+ public:
+ push_functor(It ins_it_b, It ins_it_e)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ typedef typename Cntnr::const_reference const_reference;
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ c.push(const_reference(ins_it->first));
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ };
+
+ template<typename It, class Cntnr>
+ class push_functor<It, Cntnr, __gnu_pbds::test::native_pq_tag>
+ {
+ public:
+ push_functor(It ins_it_b, It ins_it_e)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ typedef typename Cntnr::const_reference const_reference;
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ c.push(const_reference(ins_it->first));
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ };
+
+
+ template<typename It, class Cntnr>
+ class push_modify_functor<It, Cntnr, __gnu_pbds::binary_heap_tag>
+ {
+ private:
+ typedef typename Cntnr::iterator iterator;
+ typedef typename Cntnr::const_reference const_reference;
+ typedef typename Cntnr::value_type value_type;
+
+ public:
+ push_modify_functor(It ins_it_b, It ins_it_e, value_type mod_val)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e), m_mod_val(mod_val)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+ It ins_it;
+ for (ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ c.push(const_reference(ins_it->first));
+
+ for (ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ {
+ bool modified = false;
+ for (iterator it = c.begin(); !modified && it != c.end(); ++it)
+ if (*it == ins_it->first)
+ {
+ c.modify(it, m_mod_val);
+ modified = true;
+ }
+ }
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ const value_type m_mod_val;
+ };
+
+ template<typename It, class Cntnr>
+ class push_modify_functor<It, Cntnr, __gnu_pbds::test::native_pq_tag>
+ {
+ private:
+ typedef typename Cntnr::value_type value_type;
+ typedef typename Cntnr::const_reference const_reference;
+
+ public:
+ push_modify_functor(It ins_it_b, It ins_it_e, value_type mod_val)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e), m_mod_val(mod_val)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr c;
+ It ins_it;
+ for (ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ c.push(const_reference(ins_it->first));
+ for (ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ c.modify(ins_it->first, m_mod_val);
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ const value_type m_mod_val;
+ };
+ } // namespace detail
+
+ template<typename It>
+ class modify_test : private __gnu_pbds::test::detail::timing_test_base
+ {
+ public:
+ modify_test(It b, size_t vn, size_t vs, size_t vm, bool modify_up)
+ : m_ins_b(b), m_ins_vn(vn), m_ins_vs(vs), m_ins_vm(vm),
+ m_modify_up(modify_up)
+ { }
+
+ template<typename Cntnr>
+ void
+ operator()(Cntnr);
+
+ private:
+ modify_test(const modify_test&);
+
+ template<typename Cntnr>
+ void
+ modify(Cntnr, It ins_it_b, It ins_it_e)
+ {
+ typedef typename Cntnr::const_reference const_reference;
+ Cntnr cntnr;
+ for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
+ cntnr.modify(const_reference(*ins_it));
+ }
+
+ const It m_ins_b;
+ const size_t m_ins_vn;
+ const size_t m_ins_vs;
+ const size_t m_ins_vm;
+ const bool m_modify_up;
+ };
+
+ template<typename It>
+ template<typename Cntnr>
+ void
+ modify_test<It>::
+ operator()(Cntnr)
+ {
+ typedef typename Cntnr::value_type value_type;
+ typedef typename Cntnr::container_category container_category;
+ typedef typename Cntnr::const_reference const_reference;
+ typedef detail::timing_test_base timing_test_base;
+ typedef detail::push_functor<It, Cntnr, container_category> psh_fnct;
+ typedef detail::push_modify_functor<It, Cntnr, container_category> psh_mod_fnct;
+ typedef xml_result_set_performance_formatter formatter_type;
+ formatter_type res_set_fmt(string_form<Cntnr>::name(),
+ string_form<Cntnr>::desc());
+
+ for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i)
+ {
+ const size_t v = m_ins_vn + i * m_ins_vs;
+ It b = m_ins_b;
+ It e = m_ins_b;
+ std::advance(e, v);
+
+ psh_fnct psh_fn(b, e);
+ const double psh_res = timing_test_base::operator()(psh_fn);
+
+ value_type val = b->first;
+ {
+ Cntnr mod_val_container;
+ for (It mod_val_it = b; mod_val_it != e; ++mod_val_it)
+ {
+ value_type pot = mod_val_it->first;
+ if (m_modify_up == mod_val_container.get_cmp_fn()(val, pot))
+ val = pot;
+ }
+ }
+
+ psh_mod_fnct psh_mod_fn(b, e, val);
+ const double psh_mod_res = timing_test_base::operator()(psh_mod_fn);
+
+ const double min_res = double(timing_test_base::min_time_res());
+ const double effective_delta = std::max(psh_mod_res - psh_res,
+ min_res);
+
+ res_set_fmt.add_res(v, effective_delta / v);
+ }
+ }
+ } // namespace test
+} // namespace __gnu_pbds
+
+#endif
+
diff --git a/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_pop_test.hpp b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_pop_test.hpp
new file mode 100644
index 000000000..d3a9a736e
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_pop_test.hpp
@@ -0,0 +1,141 @@
+// -*- C++ -*-
+
+// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
+
+// Permission to use, copy, modify, sell, and distribute this software
+// is hereby granted without fee, provided that the above copyright
+// notice appears in all copies, and that both that copyright notice
+// and this permission notice appear in supporting documentation. None
+// of the above authors, nor IBM Haifa Research Laboratories, make any
+// representation about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+
+/**
+ * @file push_pop_test.hpp
+ * Contains a push performance test.
+ */
+
+#ifndef PB_DS_PUSH_TEST_HPP
+#define PB_DS_PUSH_TEST_HPP
+
+#include <performance/time/timing_test_base.hpp>
+#include <ext/pb_ds/detail/type_utils.hpp>
+#include <performance/io/xml_formatter.hpp>
+#include <common_type/priority_queue/string_form.hpp>
+#include <iterator>
+
+namespace __gnu_pbds
+{
+ namespace test
+ {
+ namespace detail
+ {
+ template<typename It, class Cntnr>
+ class push_pop_push_pop_functor
+ {
+ public:
+ push_pop_push_pop_functor(It ins_it_b, It ins_it_e)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr cntnr;
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ cntnr.push((typename Cntnr::const_reference)(ins_it->first));
+ while (!cntnr.empty())
+ cntnr.pop();
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ };
+
+ } // namespace detail
+
+ template<typename It>
+ class push_pop_test : private __gnu_pbds::test::detail::timing_test_base
+ {
+ public:
+ push_pop_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm)
+ : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(ins_vs), m_ins_vm(ins_vm)
+ { }
+
+ template<typename Cntnr>
+ void
+ operator()(Cntnr);
+
+ private:
+ push_pop_test(const push_pop_test&);
+
+ template<typename Cntnr>
+ void
+ push(Cntnr, It ins_it_b, It ins_it_e)
+ {
+ Cntnr cntnr;
+ for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
+ cntnr.push((typename Cntnr::const_reference)(*ins_it));
+ }
+
+ const It m_ins_b;
+ const size_t m_ins_vn;
+ const size_t m_ins_vs;
+ const size_t m_ins_vm;
+ };
+
+
+ template<typename It>
+ template<typename Cntnr>
+ void
+ push_pop_test<It>::
+ operator()(Cntnr)
+ {
+ typedef xml_result_set_performance_formatter formatter_type;
+ formatter_type res_set_fmt(string_form<Cntnr>::name(),
+ string_form<Cntnr>::desc());
+
+ for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i)
+ {
+ const size_t v = m_ins_vn + i * m_ins_vs;
+ It ins_it_b = m_ins_b;
+ It ins_it_e = m_ins_b;
+ std::advance(ins_it_e, v);
+
+ __gnu_pbds::test::detail::push_pop_push_pop_functor<It, Cntnr>
+ fn(ins_it_b, ins_it_e);
+
+ const double res =
+ __gnu_pbds::test::detail::timing_test_base::operator()(fn);
+
+ res_set_fmt.add_res(v, res / v);
+ }
+ }
+ } // namespace test
+} // namespace __gnu_pbds
+
+#endif
+
diff --git a/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_test.hpp b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_test.hpp
new file mode 100644
index 000000000..b398a7549
--- /dev/null
+++ b/libstdc++-v3/testsuite/util/performance/priority_queue/timing/push_test.hpp
@@ -0,0 +1,144 @@
+// -*- C++ -*-
+
+// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License as published by the Free Software
+// Foundation; either version 3, or (at your option) any later
+// version.
+
+// This library is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+
+// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
+
+// Permission to use, copy, modify, sell, and distribute this software
+// is hereby granted without fee, provided that the above copyright
+// notice appears in all copies, and that both that copyright notice
+// and this permission notice appear in supporting documentation. None
+// of the above authors, nor IBM Haifa Research Laboratories, make any
+// representation about the suitability of this software for any
+// purpose. It is provided "as is" without express or implied
+// warranty.
+
+/**
+ * @file push_test.hpp
+ * Contains a push performance test.
+ */
+
+#ifndef PB_DS_PUSH_TEST_HPP
+#define PB_DS_PUSH_TEST_HPP
+
+#include <performance/time/timing_test_base.hpp>
+#include <ext/pb_ds/detail/type_utils.hpp>
+#include <performance/io/xml_formatter.hpp>
+#include <common_type/priority_queue/string_form.hpp>
+#include <iterator>
+
+namespace __gnu_pbds
+{
+ namespace test
+ {
+ namespace detail
+ {
+ template<typename It, class Cntnr>
+ class push_push_functor
+ {
+ public:
+ push_push_functor(It ins_it_b, It ins_it_e)
+ : m_ins_it_b(ins_it_b), m_ins_it_e(ins_it_e)
+ { }
+
+ void
+ operator()(std::size_t resolution)
+ {
+ for (std::size_t i = 0; i < resolution; ++i)
+ {
+ Cntnr cntnr;
+ for (It ins_it = m_ins_it_b; ins_it != m_ins_it_e; ++ins_it)
+ cntnr.push((typename Cntnr::const_reference)(ins_it->first));
+ }
+ }
+
+ private:
+ const It m_ins_it_b;
+ const It m_ins_it_e;
+ };
+ } // namespace detail
+
+ template<typename It>
+ class push_test : private __gnu_pbds::test::detail::timing_test_base
+ {
+ public:
+ push_test(It ins_b, size_t ins_vn, size_t ins_vs, size_t ins_vm)
+ : m_ins_b(ins_b), m_ins_vn(ins_vn), m_ins_vs(ins_vs), m_ins_vm(ins_vm)
+ { }
+
+ template<typename Cntnr>
+ void
+ operator()(Cntnr);
+
+ private:
+ push_test(const push_test& );
+
+ template<typename Cntnr>
+ void
+ push(Cntnr, It ins_it_b, It ins_it_e);
+
+ const It m_ins_b;
+ const size_t m_ins_vn;
+ const size_t m_ins_vs;
+ const size_t m_ins_vm;
+ };
+
+
+ template<typename It>
+ template<typename Cntnr>
+ void
+ push_test<It>::
+ operator()(Cntnr)
+ {
+ typedef xml_result_set_performance_formatter formatter_type;
+ formatter_type res_set_fmt(string_form<Cntnr>::name(),
+ string_form<Cntnr>::desc());
+
+ for (size_t i = 0; m_ins_vn + i * m_ins_vs < m_ins_vm; ++i)
+ {
+ const size_t v = m_ins_vn + i * m_ins_vs;
+ It ins_it_b = m_ins_b;
+ It ins_it_e = m_ins_b;
+ std::advance(ins_it_e, v);
+
+ __gnu_pbds::test::detail::push_push_functor<It, Cntnr>
+ fn(ins_it_b, ins_it_e);
+
+ const double res =
+ __gnu_pbds::test::detail::timing_test_base::operator()(fn);
+
+ res_set_fmt.add_res(v, res / v);
+ }
+ }
+
+ template<typename It>
+ template<typename Cntnr>
+ void
+ push_test<It>::
+ push(Cntnr, It ins_it_b, It ins_it_e)
+ {
+ Cntnr cntnr;
+ for (It ins_it = ins_it_b; ins_it != ins_it_e; ++ins_it)
+ cntnr.push((typename Cntnr::const_reference)(*ins_it));
+ }
+ } // namespace test
+} // namespace __gnu_pbds
+
+#endif
+