diff options
author | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-07 21:48:01 +0000 |
---|---|---|
committer | paolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-07-07 21:48:01 +0000 |
commit | 8cbb7faaad12fcaa9ee7fec9fac48c5939d9c56d (patch) | |
tree | ada7289afa96cb40c16f8be542b8129e99b4a7a3 /libstdc++-v3/testsuite | |
parent | b5f5c5e8be1f22e01fbc9ed541241d6085a78b68 (diff) | |
download | gcc-8cbb7faaad12fcaa9ee7fec9fac48c5939d9c56d.tar.gz |
2004-07-07 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/16401
* include/bits/sstream.tcc (overflow): When reallocating _M_string
use an exponential grow policy.
* testsuite/27_io/basic_stringbuf/overflow/char/1.cc: New.
* testsuite/performance/27_io/stringbuf_overflow.cc: New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@84235 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3/testsuite')
-rw-r--r-- | libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc | 57 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/performance/27_io/stringbuf_overflow.cc | 60 |
2 files changed, 117 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc new file mode 100644 index 00000000000..d1608649b80 --- /dev/null +++ b/libstdc++-v3/testsuite/27_io/basic_stringbuf/overflow/char/1.cc @@ -0,0 +1,57 @@ +// 2004-07-07 Paolo Carlini <pcarlini@suse.de> + +// Copyright (C) 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// USA. + +// 27.7.1.3 basic_stringbuf overridden virtual functions. + +#include <sstream> +#include <cstdlib> +#include <testsuite_hooks.h> + +using namespace std; + +string +data(unsigned len) +{ + string ret; + for (unsigned i = 0; i < len; ++i) + ret.push_back('a' + rand() % 26); + return ret; +} + +void +test01(unsigned iter) +{ + bool test __attribute__((unused)) = true; + + for (unsigned n = 1; n <= iter; n *= 10) + { + const string str = data(n); + stringbuf sstr; + for (unsigned i = 0; i < n; ++i) + sstr.sputc(str[i]); + VERIFY( str == sstr.str() ); + } +} + +int main() +{ + test01(10000000); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/stringbuf_overflow.cc b/libstdc++-v3/testsuite/performance/27_io/stringbuf_overflow.cc new file mode 100644 index 00000000000..21b53625c67 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/stringbuf_overflow.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2004 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// 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 <sstream> +#include <testsuite_performance.h> + +// libstdc++/16401 ostringstream in gcc 3.4.x very slow for big data +void test01() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + for(unsigned n = 10000; n <= 10000000; n *= 10) + { + ostringstream oss; + oss << "size = " << n; + + ostringstream str; + start_counters(time, resource); + for(unsigned i = 0; i < n; ++i) + str << 'a'; + stop_counters(time, resource); + + report_performance(__FILE__, oss.str(), time, resource); + clear_counters(time, resource); + } +} + +int main() +{ + test01(); + return 0; +} |