From 15ecde8ebfba0d40217669303af29182fbf4ca5b Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Sat, 5 Aug 2006 10:11:13 +0000 Subject: [PATCH] re PR libstdc++/28587 (vector is extremely slow (900x slower than it should be)) 2006-08-05 Paolo Carlini PR libstdc++/28587 * include/bits/stl_bvector.h (vector::_M_fill): New. (vector::_M_fill_insert): Use it. * testsuite/performance/23_containers/resize/vector_bool.cc: New. * testsuite/23_containers/vector/bool/modifiers/insert/1.cc: New. * testsuite/23_containers/vector/bool/capacity/1.cc: Likewise. From-SVN: r115947 --- libstdc++-v3/ChangeLog | 10 + libstdc++-v3/include/bits/stl_bvector.h | 17 +- .../23_containers/vector/bool/capacity/1.cc | 138 ++++++++++++++ .../vector/bool/modifiers/insert/1.cc | 172 ++++++++++++++++++ .../23_containers/resize/vector_bool.cc | 49 +++++ 5 files changed, 384 insertions(+), 2 deletions(-) create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc create mode 100644 libstdc++-v3/testsuite/performance/23_containers/resize/vector_bool.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 4958cf77ecf..1d87705120b 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2006-08-05 Paolo Carlini + + PR libstdc++/28587 + * include/bits/stl_bvector.h (vector::_M_fill): New. + (vector::_M_fill_insert): Use it. + * testsuite/performance/23_containers/resize/vector_bool.cc: New. + + * testsuite/23_containers/vector/bool/modifiers/insert/1.cc: New. + * testsuite/23_containers/vector/bool/capacity/1.cc: Likewise. + 2006-08-04 Paolo Carlini * include/bits/stl_queue.h (priority_queue<>::push, diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index ab65710a1fb..02aa44cd0f0 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -740,6 +740,19 @@ template protected: + void + _M_fill(iterator __first, iterator __last, bool __x) + { + if (__first._M_p != __last._M_p) + { + std::fill(__first._M_p + 1, __last._M_p, __x ? ~0 : 0); + std::fill(__first, iterator(__first._M_p + 1, 0), __x); + std::fill(iterator(__last._M_p, 0), __last, __x); + } + else + std::fill(__first, __last, __x); + } + void _M_initialize(size_type __n) { @@ -873,7 +886,7 @@ template { std::copy_backward(__position, end(), this->_M_impl._M_finish + difference_type(__n)); - std::fill(__position, __position + difference_type(__n), __x); + _M_fill(__position, __position + difference_type(__n), __x); this->_M_impl._M_finish += difference_type(__n); } else @@ -881,7 +894,7 @@ template const size_type __len = size() + std::max(size(), __n); _Bit_type * __q = this->_M_allocate(__len); iterator __i = std::copy(begin(), __position, iterator(__q, 0)); - std::fill_n(__i, __n, __x); + _M_fill(__i, __i + difference_type(__n), __x); this->_M_impl._M_finish = std::copy(__position, end(), __i + difference_type(__n)); this->_M_deallocate(); diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc new file mode 100644 index 00000000000..c4993357dda --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/1.cc @@ -0,0 +1,138 @@ +// 2006-08-05 Paolo Carlini + +// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.5 vector resize + +#include +#include + +const bool A1[] = {0};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, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +const bool A10[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1}; +const bool A11[] = {0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); +const unsigned N10 = sizeof(A10) / sizeof(bool); +const unsigned N11 = sizeof(A11) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector vec_type; + + vec_type v; + + v.resize(1); + VERIFY( v.size() == 1 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + v.resize(3); + VERIFY( v.size() == 3 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + v.resize(2); + VERIFY( v.size() == 2 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + v.resize(7, true); + VERIFY( v.size() == 7 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + v.resize(18, false); + VERIFY( v.size() == 18 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + v.resize(40, true); + VERIFY( v.size() == 40 ); + VERIFY( std::equal(v.begin(), v.end(), A6) ); + + v.resize(80, false); + VERIFY( v.size() == 80 ); + VERIFY( std::equal(v.begin(), v.end(), A7) ); + + v.resize(90, true); + VERIFY( v.size() == 90 ); + VERIFY( std::equal(v.begin(), v.end(), A8) ); + + v.resize(100, false); + VERIFY( v.size() == 100 ); + VERIFY( std::equal(v.begin(), v.end(), A9) ); + + v.resize(200, true); + VERIFY( v.size() == 200 ); + VERIFY( std::equal(v.begin(), v.end(), A10) ); + + v.resize(13, true); + VERIFY( v.size() == 13 ); + VERIFY( std::equal(v.begin(), v.end(), A11) ); + + v.resize(13, false); + VERIFY( v.size() == 13 ); + VERIFY( std::equal(v.begin(), v.end(), A11) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc new file mode 100644 index 00000000000..b0193695f58 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/insert/1.cc @@ -0,0 +1,172 @@ +// 2006-08-05 Paolo Carlini + +// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 23.2.5 vector insert + +#include +#include + +const bool A1[] = {1, 1, 1, 1, 1, 1, 1}; +const bool A2[] = {1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1}; +const bool A3[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1}; +const bool A4[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 1}; +const bool A5[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 1, 0}; + +const unsigned N1 = sizeof(A1) / sizeof(bool); +const unsigned N2 = sizeof(A2) / sizeof(bool); +const unsigned N3 = sizeof(A3) / sizeof(bool); +const unsigned N4 = sizeof(A4) / sizeof(bool); +const unsigned N5 = sizeof(A5) / sizeof(bool); +const unsigned N6 = sizeof(A6) / sizeof(bool); +const unsigned N7 = sizeof(A7) / sizeof(bool); +const unsigned N8 = sizeof(A8) / sizeof(bool); +const unsigned N9 = sizeof(A9) / sizeof(bool); + +void +test01() +{ + bool test __attribute__((unused)) = true; + + typedef std::vector vec_type; + + vec_type v; + + v.insert(v.begin(), 7, true); + VERIFY( v.size() == 7 ); + VERIFY( std::equal(v.begin(), v.end(), A1) ); + + v.insert(v.begin() + 5, 10, false); + VERIFY( v.size() == 17 ); + VERIFY( std::equal(v.begin(), v.end(), A2) ); + + v.insert(v.begin(), 20, false); + VERIFY( v.size() == 37 ); + VERIFY( std::equal(v.begin(), v.end(), A3) ); + + v.insert(v.begin(), 40, true); + VERIFY( v.size() == 77 ); + VERIFY( std::equal(v.begin(), v.end(), A4) ); + + v.insert(v.begin() + 18, 80, false); + VERIFY( v.size() == 157 ); + VERIFY( std::equal(v.begin(), v.end(), A5) ); + + v.insert(v.begin() + 54, 80, true); + VERIFY( v.size() == 237 ); + VERIFY( std::equal(v.begin(), v.end(), A6) ); + + v.insert(v.end(), 1, false); + VERIFY( v.size() == 238 ); + VERIFY( std::equal(v.begin(), v.end(), A7) ); + + v.insert(v.begin(), 1, false); + VERIFY( v.size() == 239 ); + VERIFY( std::equal(v.begin(), v.end(), A8) ); + + v.insert(v.begin(), 180, true); + VERIFY( v.size() == 419 ); + VERIFY( std::equal(v.begin(), v.end(), A9) ); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/resize/vector_bool.cc b/libstdc++-v3/testsuite/performance/23_containers/resize/vector_bool.cc new file mode 100644 index 00000000000..7f5ab9ce861 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/resize/vector_bool.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2006 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 2, 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 COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// As a special exception, you may use this file as part of a free software +// library without restriction. Specifically, if other files instantiate +// templates or use macros or inline functions from this file, or you compile +// this file and link it with other files to produce an executable, this +// file does not by itself cause the resulting executable to be covered by +// the GNU General Public License. This exception does not however +// invalidate any other reasons why the executable file might be covered by +// the GNU General Public License. + +#include +#include + +// libstdc++/28587 +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + start_counters(time, resource); + for (unsigned i = 0; i < 200000; ++i) + { + std::vector vec; + vec.resize(i); + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +}