Commit 6004c17b by François Dumont

libstdc++: Rework std::copy/copy_backward/move/move_backward/fill/fill_n algos

Enhance those algos overloads to generalize existing optimization for
__gnu_debug::_Safe_iterator w/o _GLIBCXX_DEBUG mode and for std::deque
 iterators.

Also extend __copy_move_a2 ostreambuf_iterator overloads to std::vector and
std::deque iterators.

	* include/bits/stl_algobase.h
	(__copy_move_a1<>(_II, _II, _OI)): New.
	(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__copy_move_a1<>(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_a<>(_II, _II, _OI)): Adapt, call __copy_move_a1<>.
	(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__copy_move_a<>(_II, _II, const _Safe_iterator<>&)): New.
	(copy, move): Adapt, call __copy_move_a.
	(__copy_move_backward_a1<>(_II, _II, _OI)): New,
	call __copy_move_backward_a2.
	(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__copy_move_backward_a1<>(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_backward_a<>(_II, _II, _OI)): Adapt, call
	__copy_move_backward_a1<>.
	(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__copy_move_backward_a<>(_II, _II, const _Safe_iterator<>&)): New.
	(copy_backward, move_backward): Adapt, call __copy_move_backward_a<>.
	(__fill_a): Rename into...
	(__fill_a1): ... this.
	(__fill_a1(__normal_iterator<>, __normal_iterator<>, const _Tp&)): New.
	(__fill_a1(const _Deque_iterator<>&, const _Deque_iterator<>&, _VTp)):
	New.
	(__fill_a(_FIte, _FIte, const _Tp&)): New, call __fill_a1.
	(__fill_a(const _Safe_iterator<>&, const _Safe_iterator<>&,
	const _Tp&)): New.
	(fill): Adapt, remove __niter_base usage.
	(__fill_n_a): Rename into...
	(__fill_n_a1): ...this.
	(__fill_n_a(const _Safe_iterator<>&, _Size, const _Tp&,
	input_iterator_tag)): New.
	(__fill_n_a(_OI, _Size, const _Tp&, output_iterator_tag)): New, call
	__fill_n_a1.
	(__fill_n_a(_OI, _Size, const _Tp&, random_access_iterator_tag)): New,
	call __fill_a.
	(__equal_aux): Rename into...
	(__equal_aux1): ...this.
	(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
	(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>,
	_Deque_iterator<>)): New.
	(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
	(__equal_aux(_II1, _II1, _II2)): New, call __equal_aux1.
	(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
	_OI)): New.
	(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
	 const _Safe_iterator<>&)): New.
	(__equal_aux(_II, _II, const _Safe_iterator<>&)): New.
	(equal(_II1, _II1, _II2)): Adapt.
	* include/bits/stl_deque.h
	(fill, copy, copy_backward, move, move_backward): Remove.
	* include/bits/deque.tcc: Include <bits/stl_algobase.h>.
	(__fill_a1): New.
	(__copy_move_dit): New.
	(__copy_move_a1): New, use latter.
	(__copy_move_a1(_II, _II, _Deque_iterator<>)): New.
	(__copy_move_backward_dit): New.
	(__copy_move_backward_a1): New, use latter.
	(__copy_move_backward_a1(_II, _II, _Deque_iterator<>)): New.
	(__equal_dit): New.
	(__equal_aux1): New, use latter.
	(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
	* include/std/numeric (__is_random_access_iter): Move...
	* include/bits/stl_iterator_base_types.h (__is_random_access_iter): ...
	here. Provide pre-C++11 definition.
	* include/debug/debug.h (_Safe_iterator<>): New declaration.
	* include/debug/safe_iterator.h (_Safe_iterator<>::_M_can_advance): Add
	__strict parameter.
	* include/debug/safe_iterator.tcc: Include <bits/stl_algobase.h>.
	(_Safe_iterator<>::_M_can_advance): Adapt.
	(std::__copy_move_a, std::__copy_move_backward_a, __fill_a): New.
	(__fill_n_a, __equal_aux): New.
	* include/debug/stl_iterator.h (__niter_base): Remove.
	* include/debug/vector (__niter_base): Remove.
	* testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc:
	Include <vector> and <list>. Add benches.
	* testsuite/performance/25_algorithms/copy_deque_iterators.cc: Likewise.
	* testsuite/performance/25_algorithms/equal_deque_iterators.cc: Likewise.
	* testsuite/25_algorithms/copy/debug/1_neg.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/31.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/32.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/33.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/41.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/42.cc: New.
	* testsuite/25_algorithms/copy/deque_iterators/43.cc: New.
	* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc (test02):
	New.
	* testsuite/25_algorithms/copy_backward/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/equal/deque_iterators/1.cc: New.
	* testsuite/25_algorithms/fill/deque_iterators/1.cc: New.
	* testsuite/25_algorithms/move/deque_iterators/2.cc: New.
	* testsuite/25_algorithms/move_backward/deque_iterators/2.cc: New.

From-SVN: r279201
parent 5e72bcc1
2019-12-10 François Dumont <fdumont@gcc.gnu.org>
* include/bits/stl_algobase.h
(__copy_move_a1<>(_II, _II, _OI)): New.
(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
(__copy_move_a1<>(_Deque_iterator<>, _Deque_iterator<>,
_Deque_iterator<>)): New.
(__copy_move_a1<>(_II, _II, _Deque_iterator<>)): New.
(__copy_move_a<>(_II, _II, _OI)): Adapt, call __copy_move_a1<>.
(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
_OI)): New.
(__copy_move_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
const _Safe_iterator<>&)): New.
(__copy_move_a<>(_II, _II, const _Safe_iterator<>&)): New.
(copy, move): Adapt, call __copy_move_a.
(__copy_move_backward_a1<>(_II, _II, _OI)): New,
call __copy_move_backward_a2.
(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
(__copy_move_backward_a1<>(_Deque_iterator<>, _Deque_iterator<>,
_Deque_iterator<>)): New.
(__copy_move_backward_a1<>(_II, _II, _Deque_iterator<>)): New.
(__copy_move_backward_a<>(_II, _II, _OI)): Adapt, call
__copy_move_backward_a1<>.
(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
_OI)): New.
(__copy_move_backward_a<>(const _Safe_iterator<>&, const _Safe_iterator<>&,
const _Safe_iterator<>&)): New.
(__copy_move_backward_a<>(_II, _II, const _Safe_iterator<>&)): New.
(copy_backward, move_backward): Adapt, call __copy_move_backward_a<>.
(__fill_a): Rename into...
(__fill_a1): ... this.
(__fill_a1(__normal_iterator<>, __normal_iterator<>, const _Tp&)): New.
(__fill_a1(const _Deque_iterator<>&, const _Deque_iterator<>&, _VTp)):
New.
(__fill_a(_FIte, _FIte, const _Tp&)): New, call __fill_a1.
(__fill_a(const _Safe_iterator<>&, const _Safe_iterator<>&,
const _Tp&)): New.
(fill): Adapt, remove __niter_base usage.
(__fill_n_a): Rename into...
(__fill_n_a1): ...this.
(__fill_n_a(const _Safe_iterator<>&, _Size, const _Tp&,
input_iterator_tag)): New.
(__fill_n_a(_OI, _Size, const _Tp&, output_iterator_tag)): New, call
__fill_n_a1.
(__fill_n_a(_OI, _Size, const _Tp&, random_access_iterator_tag)): New,
call __fill_a.
(__equal_aux): Rename into...
(__equal_aux1): ...this.
(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>, _OI)): New.
(__equal_aux1(_Deque_iterator<>, _Deque_iterator<>,
_Deque_iterator<>)): New.
(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
(__equal_aux(_II1, _II1, _II2)): New, call __equal_aux1.
(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
_OI)): New.
(__equal_aux(const _Safe_iterator<>&, const _Safe_iterator<>&,
const _Safe_iterator<>&)): New.
(__equal_aux(_II, _II, const _Safe_iterator<>&)): New.
(equal(_II1, _II1, _II2)): Adapt.
* include/bits/stl_deque.h
(fill, copy, copy_backward, move, move_backward): Remove.
* include/bits/deque.tcc: Include <bits/stl_algobase.h>.
(__fill_a1): New.
(__copy_move_dit): New.
(__copy_move_a1): New, use latter.
(__copy_move_a1(_II, _II, _Deque_iterator<>)): New.
(__copy_move_backward_dit): New.
(__copy_move_backward_a1): New, use latter.
(__copy_move_backward_a1(_II, _II, _Deque_iterator<>)): New.
(__equal_dit): New.
(__equal_aux1): New, use latter.
(__equal_aux1(_II, _II, _Deque_iterator<>)): New.
* include/std/numeric (__is_random_access_iter): Move...
* include/bits/stl_iterator_base_types.h (__is_random_access_iter): ...
here. Provide pre-C++11 definition.
* include/debug/debug.h (_Safe_iterator<>): New declaration.
* include/debug/safe_iterator.h (_Safe_iterator<>::_M_can_advance): Add
__strict parameter.
* include/debug/safe_iterator.tcc: Include <bits/stl_algobase.h>.
(_Safe_iterator<>::_M_can_advance): Adapt.
(std::__copy_move_a, std::__copy_move_backward_a, __fill_a): New.
(__fill_n_a, __equal_aux): New.
* include/debug/stl_iterator.h (__niter_base): Remove.
* include/debug/vector (__niter_base): Remove.
* testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc:
Include <vector> and <list>. Add benches.
* testsuite/performance/25_algorithms/copy_deque_iterators.cc: Likewise.
* testsuite/performance/25_algorithms/equal_deque_iterators.cc: Likewise.
* testsuite/25_algorithms/copy/debug/1_neg.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/2.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/31.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/32.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/33.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/41.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/42.cc: New.
* testsuite/25_algorithms/copy/deque_iterators/43.cc: New.
* testsuite/25_algorithms/copy/streambuf_iterators/char/4.cc (test02):
New.
* testsuite/25_algorithms/copy_backward/deque_iterators/2.cc: New.
* testsuite/25_algorithms/equal/deque_iterators/1.cc: New.
* testsuite/25_algorithms/fill/deque_iterators/1.cc: New.
* testsuite/25_algorithms/move/deque_iterators/2.cc: New.
* testsuite/25_algorithms/move_backward/deque_iterators/2.cc: New.
2019-12-10 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/92886
......
......@@ -373,77 +373,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
{ return __x + __n; }
};
template<typename _Tp>
void
fill(const _Deque_iterator<_Tp, _Tp&, _Tp*>&,
const _Deque_iterator<_Tp, _Tp&, _Tp*>&, const _Tp&);
template<typename _Tp>
_Deque_iterator<_Tp, _Tp&, _Tp*>
copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, _Tp&, _Tp*>);
template<typename _Tp>
inline _Deque_iterator<_Tp, _Tp&, _Tp*>
copy(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
{ return std::copy(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
__result); }
template<typename _Tp>
_Deque_iterator<_Tp, _Tp&, _Tp*>
copy_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, _Tp&, _Tp*>);
template<typename _Tp>
inline _Deque_iterator<_Tp, _Tp&, _Tp*>
copy_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
{ return std::copy_backward(_Deque_iterator<_Tp,
const _Tp&, const _Tp*>(__first),
_Deque_iterator<_Tp,
const _Tp&, const _Tp*>(__last),
__result); }
#if __cplusplus >= 201103L
template<typename _Tp>
_Deque_iterator<_Tp, _Tp&, _Tp*>
move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, _Tp&, _Tp*>);
template<typename _Tp>
inline _Deque_iterator<_Tp, _Tp&, _Tp*>
move(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
{ return std::move(_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__first),
_Deque_iterator<_Tp, const _Tp&, const _Tp*>(__last),
__result); }
template<typename _Tp>
_Deque_iterator<_Tp, _Tp&, _Tp*>
move_backward(_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, const _Tp&, const _Tp*>,
_Deque_iterator<_Tp, _Tp&, _Tp*>);
template<typename _Tp>
inline _Deque_iterator<_Tp, _Tp&, _Tp*>
move_backward(_Deque_iterator<_Tp, _Tp&, _Tp*> __first,
_Deque_iterator<_Tp, _Tp&, _Tp*> __last,
_Deque_iterator<_Tp, _Tp&, _Tp*> __result)
{ return std::move_backward(_Deque_iterator<_Tp,
const _Tp&, const _Tp*>(__first),
_Deque_iterator<_Tp,
const _Tp&, const _Tp*>(__last),
__result); }
#endif
/**
* Deque base class. This class provides the unified face for %deque's
* allocation. This class's constructor and destructor allocate and
......
......@@ -249,10 +249,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
using _RequireInputIter =
__enable_if_t<is_convertible<__iterator_category_t<_InIter>,
input_iterator_tag>::value>;
template<typename _It,
typename _Cat = __iterator_category_t<_It>>
struct __is_random_access_iter
: is_base_of<random_access_iterator_tag, _Cat>
{
typedef is_base_of<random_access_iterator_tag, _Cat> _Base;
enum { __value = _Base::value };
};
#else
template<typename _It, typename _Traits = iterator_traits<_It>,
typename _Cat = typename _Traits::iterator_category>
struct __is_random_access_iter
{ enum { __value = __is_base_of(random_access_iterator_tag, _Cat) }; };
#endif
_GLIBCXX_END_NAMESPACE_VERSION
} // namespace
#endif /* _STL_ITERATOR_BASE_TYPES_H */
......@@ -56,6 +56,9 @@ namespace std
namespace __gnu_debug
{
using namespace std::__debug;
template<typename _Ite, typename _Seq, typename _Cat>
struct _Safe_iterator;
}
#ifndef _GLIBCXX_DEBUG
......
......@@ -400,7 +400,7 @@ namespace __gnu_debug
// Can we advance the iterator @p __n steps (@p __n may be negative)
bool
_M_can_advance(difference_type __n) const;
_M_can_advance(difference_type __n, bool __strict = false) const;
// Is the iterator range [*this, __rhs) valid?
bool
......
......@@ -115,17 +115,4 @@ namespace __gnu_debug
#endif
}
namespace std
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Iterator, typename _Container, typename _Sequence>
_Iterator
__niter_base(const __gnu_debug::_Safe_iterator<
__gnu_cxx::__normal_iterator<_Iterator, _Container>,
_Sequence, std::random_access_iterator_tag>&);
_GLIBCXX_END_NAMESPACE_VERSION
}
#endif
......@@ -794,13 +794,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
#endif
template<typename _Iterator, typename _Container, typename _Sequence>
_Iterator
__niter_base(const __gnu_debug::_Safe_iterator<
__gnu_cxx::__normal_iterator<_Iterator, _Container>,
_Sequence, std::random_access_iterator_tag>& __it)
{ return std::__niter_base(__it.base()); }
#if __cplusplus >= 201703L
namespace __detail::__variant
{
......
......@@ -229,12 +229,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// @addtogroup numeric_ops
/// @{
/// @cond undocumented
template<typename _It, typename _Cat = __iterator_category_t<_It>>
using __is_random_access_iter
= is_base_of<random_access_iterator_tag, _Cat>;
/// @endcond
/**
* @brief Calculate reduction of values in a range.
*
......
// Copyright (C) 2019 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/>.
// 25.2.1 [lib.alg.copy] Copy.
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <list>
#include <vector>
void
test01()
{
std::list<int> l(10, 1);
std::vector<int> v(5, 0);
std::copy(++l.begin(), --l.end(), v.begin());
}
int
main()
{
test01();
return 0;
}
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<int> d;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
copy(d.begin(), d.end(), dest.begin());
VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
}
void test02()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
const deque<int>& cd = d;
copy(cd.begin(), cd.end(), dest.begin());
VERIFY( equal(dest.begin(), dest.end(), cd.begin()) );
}
void test03()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
d.pop_front();
d.pop_back();
vector<int> dest(d.size(), 0);
copy(d.begin(), d.end(), dest.begin());
VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
}
void test04()
{
using namespace std;
vector<int> v;
for (int i = 0; i != 1024; ++i)
v.push_back(i);
deque<int> dest(v.size() - 10, 0);
std::copy(v.begin() + 5, v.end() - 5, dest.begin());
VERIFY( std::equal(dest.begin(), dest.end(), v.begin() + 5) );
}
void test05()
{
using namespace std;
std::list<int> l;
for (int i = 0; i != 1024; ++i)
l.push_back(i);
std::deque<int> dest(l.size(), 0);
std::copy(l.begin(), l.end(), dest.begin());
VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) );
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <vector>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size(), 0);
const std::deque<int>& cd = d;
std::copy(cd.begin() + 10, cd.begin() + 5, dest.begin());
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <vector>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size() / 2, 0);
const std::deque<int>& cd = d;
std::copy(cd.begin(), cd.end(), dest.begin());
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <list>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::list<int> dest(d.size(), 0);
const std::deque<int>& cd = d;
std::copy(cd.begin(), cd.end(), dest.begin());
}
void test02()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::list<int> dest(d.size() / 2, 0);
std::list<int>::iterator lit = dest.begin();
const std::deque<int>& cd = d;
std::copy(cd.begin(), cd.end(), ++lit);
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <vector>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size(), 0);
std::copy(d.begin() + 10, d.begin() + 5, dest.begin());
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <vector>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size() / 2, 0);
std::copy(d.begin(), d.end(), dest.begin());
}
int main()
{
test01();
return 0;
}
// Copyright (C) 2019 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/>.
//
// { dg-do run { xfail *-*-* } }
// { dg-require-debug-mode "" }
#include <algorithm>
#include <deque>
#include <list>
#include <testsuite_hooks.h>
void test01()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::list<int> dest(d.size(), 0);
std::copy(d.begin(), d.end(), dest.begin());
}
void test02()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::list<int> dest(d.size() / 2, 0);
std::list<int>::iterator lit = dest.begin();
std::copy(d.begin(), d.end(), ++lit);
}
int main()
{
test01();
test02();
return 0;
}
......@@ -21,6 +21,8 @@
#include <fstream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <testsuite_hooks.h>
// { dg-require-fileio "" }
......@@ -33,7 +35,7 @@ void test01()
typedef istreambuf_iterator<char> in_iterator_type;
ifstream fbuf_ref("istream_unformatted-1.txt"),
fbuf("istream_unformatted-1.txt");
fbuf("istream_unformatted-1.txt");
char buffer_ref[16500],
buffer[16500];
......@@ -50,8 +52,33 @@ void test01()
VERIFY( !memcmp(buffer, buffer_ref, 16500) );
}
void test02()
{
using namespace std;
typedef istreambuf_iterator<char> in_iterator_type;
ifstream fbuf_ref("istream_unformatted-1.txt"),
fbuf("istream_unformatted-1.txt");
char buffer_ref[16500];
std::vector<char> buffer(16500, 'a');
fbuf_ref.read(buffer_ref, 16500);
in_iterator_type beg(fbuf);
in_iterator_type end;
copy(beg, end, buffer.begin());
VERIFY( fbuf_ref.good() );
VERIFY( fbuf.good() );
VERIFY( !memcmp(buffer.data(), buffer_ref, 16500) );
}
int main()
{
test01();
test02();
return 0;
}
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<int> d;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
copy_backward(d.begin(), d.end(), dest.end());
VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
}
void test02()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
const deque<int>& cd = d;
copy_backward(cd.begin(), cd.end(), dest.end());
VERIFY( equal(dest.begin(), dest.end(), cd.begin()) );
}
void test03()
{
using namespace std;
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
d.pop_front();
d.pop_back();
std::vector<int> dest(d.size(), 0);
std::copy_backward(d.begin(), d.end(), dest.end());
VERIFY( std::equal(dest.begin(), dest.end(), d.begin()) );
}
void test04()
{
using namespace std;
std::vector<int> v;
for (int i = 0; i != 1024; ++i)
v.push_back(i);
std::deque<int> dest(v.size() - 10, 0);
std::copy_backward(v.begin() + 5, v.end() - 5, dest.end());
VERIFY( std::equal(v.begin() + 5, v.end() - 5, dest.begin()) );
}
void test05()
{
using namespace std;
std::list<int> l;
for (int i = 0; i != 1024; ++i)
l.push_back(i);
std::deque<int> dest(l.size(), 0);
std::copy_backward(l.begin(), l.end(), dest.end());
VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) );
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <vector>
#include <deque>
#include <ext/new_allocator.h>
#include <ext/malloc_allocator.h>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<int> d;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
const deque<int>& cd = d;
VERIFY( equal(cd.begin(), cd.end(), cd.begin()) );
VERIFY( equal(cd.begin(), cd.end(), d.begin()) );
VERIFY( equal(d.begin(), d.end(), d.begin()) );
VERIFY( equal(d.begin(), d.end(), cd.begin()) );
}
void test02()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i % 10);
VERIFY( equal(d.begin(), d.begin() + 10, d.begin() + 20) );
VERIFY( equal(d.begin() + 10, d.end() - 10, d.begin()) );
const deque<int>& cd = d;
VERIFY( equal(cd.begin(), cd.begin() + 10, cd.begin() + 20) );
VERIFY( equal(cd.begin() + 10, cd.end() - 10, d.begin()) );
VERIFY( equal(d.begin() + 10, d.end() - 10, cd.begin()) );
}
void test03()
{
using namespace std;
deque<int> d1;
for (int i = 0; i != 1024; ++i)
d1.push_back(i % 10);
deque<int> d2(d1);
for (int i = 0; i != 10; ++i)
d2.pop_front();
VERIFY( equal(d1.begin(), d1.begin() + 10, d2.begin()) );
VERIFY( equal(d1.begin() + 10, d1.end() - 10, d2.begin()) );
const deque<int>& cd1 = d1;
const deque<int>& cd2 = d2;
VERIFY( equal(cd1.begin(), cd1.begin() + 10, cd2.begin() + 20) );
VERIFY( equal(cd1.begin() + 10, cd1.end() - 10, d2.begin()) );
VERIFY( equal(cd2.begin() + 10, cd2.end() - 10, cd1.begin()) );
}
void test04()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
vector<int> v(d.begin(), d.end());
VERIFY( equal(d.begin(), d.end(), v.begin()) );
VERIFY( equal(v.begin(), v.end(), d.begin()) );
const deque<int>& cd = d;
VERIFY( equal(cd.begin(), cd.end(), v.begin()) );
VERIFY( equal(v.begin(), v.end(), cd.begin()) );
}
void test05()
{
using namespace std;
int a[] { 0, 1, 2, 3, 4 };
deque<int, __gnu_cxx::new_allocator<int> > d1(a, a + 5);
deque<int, __gnu_cxx::malloc_allocator<int> > d2(a, a + 5);
VERIFY( equal(d1.begin(), d1.end(), d2.begin()) );
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <deque>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<char> d1;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(char)); ++i)
d1.push_back((char)i);
deque<char> d2(d1.size(), '\0');
fill(d1.begin(), d1.end(), '\0');
VERIFY( equal(d1.begin(), d1.end(), d2.begin()) );
}
void test02()
{
using namespace std;
deque<char> d1;
for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(char)); ++i)
d1.push_back(i);
deque<char> d2(d1.size(), '\0');
fill(d1.begin(), d1.end(), '\0');
VERIFY( equal(d1.begin(), d1.end(), d2.begin()) );
}
int main()
{
test01();
test02();
return 0;
}
// { dg-do run { target c++11 } }
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<int> d;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
move(d.begin(), d.end(), dest.begin());
VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
}
void test02()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
const deque<int>& cd = d;
move(cd.begin(), cd.end(), dest.begin());
VERIFY( equal(dest.begin(), dest.end(), cd.begin()) );
}
void test03()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size(), 0);
std::move(d.begin(), d.end(), dest.begin());
VERIFY( std::equal(dest.begin(), dest.end(), d.begin()) );
}
void test04()
{
std::vector<int> v;
for (int i = 0; i != 1024; ++i)
v.push_back(i);
std::deque<int> dest(v.size() - 10, 0);
std::move(v.begin() + 5, v.end() - 5, dest.begin());
VERIFY( std::equal(dest.begin(), dest.end(), v.begin() + 5) );
}
void test05()
{
std::list<int> l;
for (int i = 0; i != 1024; ++i)
l.push_back(i);
std::deque<int> dest(l.size(), 0);
std::move(l.begin(), l.end(), dest.begin());
VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) );
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
// { dg-do run { target c++11 } }
// Copyright (C) 2019 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/>.
#include <algorithm>
#include <vector>
#include <list>
#include <deque>
#include <testsuite_hooks.h>
void test01()
{
using namespace std;
deque<int> d;
for (int i = 0; i != _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
move_backward(d.begin(), d.end(), dest.end());
VERIFY( equal(dest.begin(), dest.end(), d.begin()) );
}
void test02()
{
using namespace std;
deque<int> d;
for (int i = 0; i != 4 * _GLIBCXX_STD_C::__deque_buf_size(sizeof(int)); ++i)
d.push_back(i);
deque<int> dest(d.size(), 0);
const deque<int>& cd = d;
move_backward(cd.begin(), cd.end(), dest.end());
VERIFY( equal(dest.begin(), dest.end(), cd.begin()) );
}
void test03()
{
std::deque<int> d;
for (int i = 0; i != 1024; ++i)
d.push_back(i);
std::vector<int> dest(d.size(), 0);
std::move_backward(d.begin(), d.end(), dest.end());
VERIFY( std::equal(dest.begin(), dest.end(), d.begin()) );
}
void test04()
{
std::vector<int> v;
for (int i = 0; i != 1024; ++i)
v.push_back(i);
std::deque<int> dest(v.size() - 10, 0);
std::move_backward(v.begin() + 5, v.end() - 5, dest.end());
VERIFY( std::equal(dest.begin(), dest.end(), v.begin() + 5) );
}
void test05()
{
std::list<int> l;
for (int i = 0; i != 1024; ++i)
l.push_back(i);
std::deque<int> dest(l.size(), 0);
std::move_backward(l.begin(), l.end(), dest.end());
VERIFY( std::equal(dest.begin(), dest.end(), l.begin()) );
}
int main()
{
test01();
test02();
test03();
test04();
test05();
return 0;
}
......@@ -16,6 +16,9 @@
// <http://www.gnu.org/licenses/>.
#include <deque>
#include <vector>
#include <list>
#include <testsuite_performance.h>
int main()
......@@ -34,7 +37,71 @@ int main()
for (int j = 0; j < 3000; ++j)
std::copy_backward(data.begin(), data.begin() + j, d.end());
stop_counters(time, resource);
report_performance(__FILE__, "", time, resource);
report_performance(__FILE__, "deque 2 deque", time, resource);
clear_counters(time, resource);
std::vector<int> v(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy_backward(data.begin(), data.begin() + j, v.end());
stop_counters(time, resource);
report_performance(__FILE__, "deque 2 vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy_backward(v.begin(), v.begin() + j, d.end());
stop_counters(time, resource);
report_performance(__FILE__, "vector 2 deque", time, resource);
clear_counters(time, resource);
std::vector<char> cv(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy_backward(data.begin(), data.begin() + j, cv.end());
stop_counters(time, resource);
report_performance(__FILE__, "int deque 2 char vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy_backward(cv.begin(), cv.begin() + j, d.end());
stop_counters(time, resource);
report_performance(__FILE__, "char vector 2 int deque", time, resource);
clear_counters(time, resource);
std::list<int> l(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy_backward(data.begin(), data.begin() + j, l.end());
stop_counters(time, resource);
report_performance(__FILE__, "deque 2 list", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
std::list<int>::iterator lit;
start_counters(time, resource);
for (int i = 0; i < 200; ++i)
{
lit = l.begin();
for (int j = 0; j < 3000; ++j, ++lit)
std::copy_backward(l.begin(), lit, d.end());
}
stop_counters(time, resource);
report_performance(__FILE__, "list 2 deque", time, resource);
return 0;
}
......@@ -16,6 +16,9 @@
// <http://www.gnu.org/licenses/>.
#include <deque>
#include <vector>
#include <list>
#include <testsuite_performance.h>
int main()
......@@ -34,7 +37,71 @@ int main()
for (int j = 0; j < 3000; ++j)
std::copy(data.begin(), data.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "", time, resource);
report_performance(__FILE__, "deque 2 deque", time, resource);
clear_counters(time, resource);
std::vector<int> v(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy(data.begin(), data.begin() + j, v.begin());
stop_counters(time, resource);
report_performance(__FILE__, "deque 2 vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy(v.begin(), v.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "vector 2 deque", time, resource);
clear_counters(time, resource);
std::vector<char> cv(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy(data.begin(), data.begin() + j, cv.begin());
stop_counters(time, resource);
report_performance(__FILE__, "int deque 2 char vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy(cv.begin(), cv.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "char vector 2 int deque", time, resource);
clear_counters(time, resource);
std::list<int> l(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::copy(data.begin(), data.begin() + j, l.begin());
stop_counters(time, resource);
report_performance(__FILE__, "deque 2 list", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
std::list<int>::iterator lit;
start_counters(time, resource);
for (int i = 0; i < 200; ++i)
{
lit = l.begin();
for (int j = 0; j < 3000; ++j, ++lit)
std::copy(l.begin(), lit, d.begin());
}
stop_counters(time, resource);
report_performance(__FILE__, "list 2 deque", time, resource);
return 0;
}
// Copyright (C) 2019 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/>.
#include <deque>
#include <vector>
#include <testsuite_performance.h>
int main()
{
using namespace __gnu_test;
time_counter time;
resource_counter resource;
const std::deque<int> data(3000, 1);
std::deque<int> d(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::equal(data.begin(), data.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "deque vs deque", time, resource);
clear_counters(time, resource);
std::vector<int> v(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::equal(data.begin(), data.begin() + j, v.begin());
stop_counters(time, resource);
report_performance(__FILE__, "deque vs vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::equal(v.begin(), v.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "vector vs deque", time, resource);
clear_counters(time, resource);
std::vector<char> cv(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::equal(data.begin(), data.begin() + j, cv.begin());
stop_counters(time, resource);
report_performance(__FILE__, "int deque vs char vector", time, resource);
clear_counters(time, resource);
d.assign(3000, 1);
start_counters(time, resource);
for (int i = 0; i < 1000; ++i)
for (int j = 0; j < 3000; ++j)
std::equal(cv.begin(), cv.begin() + j, d.begin());
stop_counters(time, resource);
report_performance(__FILE__, "char vector vs int deque", time, resource);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment