diff options
Diffstat (limited to 'libstdc++-v3/testsuite/performance/27_io')
15 files changed, 931 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/performance/27_io/cout_insert_int.cc b/libstdc++-v3/testsuite/performance/27_io/cout_insert_int.cc new file mode 100644 index 000000000..1ade53f51 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/cout_insert_int.cc @@ -0,0 +1,39 @@ +// Copyright (C) 2003, 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/>. + + +#include <iostream> +#include <testsuite_performance.h> + +// libstdc++/7076 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 150000; + + start_counters(time, resource); + for (int i = 0; i < iterations; i++) + std::cout << i << '\n'; + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/filebuf_copy.cc b/libstdc++-v3/testsuite/performance/27_io/filebuf_copy.cc new file mode 100644 index 000000000..090f32cc1 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/filebuf_copy.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2003, 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/>. + + +#include <cstdio> +#include <fstream> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const unsigned long count = 1ul << 30; + + // C unlocked + FILE* fpi = fopen("/dev/zero", "r"); + FILE* fpo = fopen("/dev/null", "w"); + start_counters(time, resource); + for (unsigned long i = 0; i < count; ++i) + { + int c = getc_unlocked(fpi); + if (c == EOF || putc_unlocked(c, fpo) == EOF) + break; + } + stop_counters(time, resource); + fclose(fpi); + fclose(fpo); + report_performance(__FILE__, "C unlocked", time, resource); + clear_counters(time, resource); + + // C++ + filebuf in; + in.open("/dev/zero", ios::in); + filebuf out; + out.open("/dev/null", ios::out); + start_counters(time, resource); + for (unsigned long i = 0; i < count; ++i) + { + int c = in.sbumpc(); + if (c == EOF || out.sputc(c) == EOF) + break; + } + stop_counters(time, resource); + in.close(); + out.close(); + report_performance(__FILE__, "C++", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/filebuf_sgetn_unbuf.cc b/libstdc++-v3/testsuite/performance/27_io/filebuf_sgetn_unbuf.cc new file mode 100644 index 000000000..1eb3dc5cf --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/filebuf_sgetn_unbuf.cc @@ -0,0 +1,85 @@ +// Copyright (C) 2004, 2005, 2006, 2007, 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/>. + + +#include <cstdio> +#include <cstdlib> +#include <fstream> +#include <testsuite_performance.h> + +// libstdc++/11722 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const int iterations = 500000; + const int chunksize = 100; + + char* chunk = new char[chunksize]; + const char* name1 = "/usr/share/dict/words"; + const char* name2 = "/usr/share/dict/linux.words"; + const char* name = name1; + + // C + FILE* file; + if (!(file = fopen(name, "r"))) + { + name = name2; + if (!(file = fopen(name, "r"))) + exit(1); + } + setvbuf(file, 0, _IONBF, 0); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + if (fread(chunk, 1, chunksize, file) < chunksize) + fseek(file, 0, SEEK_SET); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C", time, resource); + clear_counters(time, resource); + + // C unlocked + file = fopen(name, "r"); + setvbuf(file, 0, _IONBF, 0); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + if (fread_unlocked(chunk, 1, chunksize, file) < chunksize) + fseek(file, 0, SEEK_SET); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C unlocked", time, resource); + clear_counters(time, resource); + + // C++ + filebuf buf; + buf.pubsetbuf(0, 0); + buf.open(name, ios_base::in); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + if (buf.sgetn(chunk, chunksize) < chunksize) + buf.pubseekoff(0, ios::beg); + stop_counters(time, resource); + report_performance(__FILE__, "C++", time, resource); + + delete [] chunk; + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/filebuf_sputc.cc b/libstdc++-v3/testsuite/performance/27_io/filebuf_sputc.cc new file mode 100644 index 000000000..40600d5a7 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/filebuf_sputc.cc @@ -0,0 +1,65 @@ +// Copyright (C) 2003, 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/>. + + +#include <cstdio> +#include <fstream> +#include <testsuite_performance.h> + +// libstdc++/9876 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 100000000; + + // C + FILE* file = fopen("tmp", "w+"); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + putc(i % 100, file); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C", time, resource); + clear_counters(time, resource); + + // C unlocked + file = fopen("tmp", "w+"); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + putc_unlocked(i % 100, file); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C unlocked", time, resource); + clear_counters(time, resource); + + + // C++ + filebuf buf; + buf.open("tmp", ios_base::out | ios_base::in | ios_base::trunc); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + buf.sputc(i % 100); + stop_counters(time, resource); + report_performance(__FILE__, "C++", time, resource); + + unlink("tmp"); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/filebuf_sputn_unbuf.cc b/libstdc++-v3/testsuite/performance/27_io/filebuf_sputn_unbuf.cc new file mode 100644 index 000000000..10b1746f7 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/filebuf_sputn_unbuf.cc @@ -0,0 +1,73 @@ +// Copyright (C) 2004, 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/>. + + +#include <cstdio> +#include <fstream> +#include <testsuite_performance.h> + +// libstdc++/11378 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const int iterations = 500000; + const int chunksize = 100; + + char* chunk = new char[chunksize]; + + // C + FILE* file = fopen("tmp", "w+"); + setvbuf(file, 0, _IONBF, 0); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + fwrite(chunk, 1, chunksize, file); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C", time, resource); + clear_counters(time, resource); + + // C unlocked + file = fopen("tmp", "w+"); + setvbuf(file, 0, _IONBF, 0); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + fwrite_unlocked(chunk, 1, chunksize, file); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C unlocked", time, resource); + clear_counters(time, resource); + + // C++ + filebuf buf; + buf.pubsetbuf(0, 0); + buf.open("tmp", ios_base::out | ios_base::in | ios_base::trunc); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + buf.sputn(chunk, chunksize); + stop_counters(time, resource); + report_performance(__FILE__, "C++", time, resource); + + unlink("tmp"); + delete [] chunk; + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/fmtflags_manipulators.cc b/libstdc++-v3/testsuite/performance/27_io/fmtflags_manipulators.cc new file mode 100644 index 000000000..345fd8998 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/fmtflags_manipulators.cc @@ -0,0 +1,60 @@ +// Copyright (C) 2004, 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/>. + + +#include <cstdlib> +#include <sstream> +#include <testsuite_performance.h> + +// libstdc++/14078 +int main(int argc, char** argv) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + int iters = 50000000; + if (argc > 1) + iters = atoi(argv[1]); + + ostringstream os_s, os_m; + + // setf + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + os_s.setf(ios_base::uppercase); + os_s.unsetf(ios_base::uppercase); + } + stop_counters(time, resource); + report_performance(__FILE__, "setf", time, resource); + clear_counters(time, resource); + + // manipulator + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + os_m << uppercase; + os_m << nouppercase; + } + stop_counters(time, resource); + report_performance(__FILE__, "manipulator", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/fstream_seek_write.cc b/libstdc++-v3/testsuite/performance/27_io/fstream_seek_write.cc new file mode 100644 index 000000000..f55d53377 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/fstream_seek_write.cc @@ -0,0 +1,49 @@ +// Copyright (C) 2003, 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/>. + + +#include <fstream> +#include <testsuite_performance.h> + +// libstdc++/10672 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 300000; + + fstream s("tmp_perf_seek", ios::binary | ios::in | ios::out | ios::trunc); + if (s.good()) + { + start_counters(time, resource); + for (int i = 0; i < iterations; i++) + { + s.seekp(0); + s.write((char *) & i, sizeof(int)); + s.seekp(sizeof(int)); + s.write((char *) & i, sizeof(int)); + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + } + + unlink("tmp_perf_seek"); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_chars.cc b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_chars.cc new file mode 100644 index 000000000..f12d49774 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_chars.cc @@ -0,0 +1,82 @@ +// Copyright (C) 2005, 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/>. + + +#include <cstdio> +#include <fstream> +#include <string> +#include <testsuite_performance.h> + +// libstdc++/22515 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const char filename[] = "tmp_perf_chars.txt"; + const unsigned lines = 200000; + const unsigned line_length = 200; + + char* line = new char[line_length + 2]; + + // Construct data. + { + memset(line, 'x', line_length); + line[line_length] = '\n'; + line[line_length + 1] = '\0'; + + ofstream out(filename); + for (unsigned i = 0; i < lines; ++i) + out << line; + } + + // operator>>(basic_istream<char>& __in, basic_string<char>& __str) + { + start_counters(time, resource); + for (int iter = 0; iter < 25; ++iter) + { + ifstream file(filename); + string string_line; + + while (file >> string_line); + } + stop_counters(time, resource); + report_performance(__FILE__, "string&", time, resource); + clear_counters(time, resource); + } + + // operator>>(basic_istream<char>& __in, char* __s) + { + start_counters(time, resource); + for (int iter = 0; iter < 25; ++iter) + { + ifstream file(filename); + + while (file >> line); + } + stop_counters(time, resource); + report_performance(__FILE__, "char*", time, resource); + clear_counters(time, resource); + } + + delete[] line; + unlink(filename); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_float.cc b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_float.cc new file mode 100644 index 000000000..2df70ccd5 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_float.cc @@ -0,0 +1,67 @@ +// Copyright (C) 2004, 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/>. + + +#include <fstream> +#include <sstream> +#include <testsuite_performance.h> + +void test_extraction(int p = 6) +{ + using namespace std; + using namespace __gnu_test; + + const char* filename = "tmp_perf_float.txt"; + const int iterations = 10000000; + + ostringstream oss; + oss << "precision " << p; + + // Construct data. + { + ofstream out(filename); + out.precision(p); + for (int i = 0; i < iterations; ++i) + { + float f = i * 3.14159265358979323846; + out << f << '\n'; + } + } + + { + time_counter time; + resource_counter resource; + + ifstream in(filename); + in.precision(p); + float f; + start_counters(time, resource); + for (int j, i = 0; i < iterations; ++i) + in >> f; + stop_counters(time, resource); + report_performance(__FILE__, oss.str(), time, resource); + } + + unlink(filename); +}; + +int main() +{ + test_extraction(6); + test_extraction(12); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_int.cc b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_int.cc new file mode 100644 index 000000000..7491ad331 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ifstream_extract_int.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2003, 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/>. + + +#include <fstream> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 10000000; + + { + ofstream out("tmp_perf_int.txt"); + for (int i = 0; i < iterations; ++i) + out << i << "\n"; + } + + { + ifstream in("tmp_perf_int.txt"); + start_counters(time, resource); + for (int j, i = 0; i < iterations; ++i) + in >> j; + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + } + + unlink("tmp_perf_int.txt"); + return 0; +}; diff --git a/libstdc++-v3/testsuite/performance/27_io/ifstream_getline-2.cc b/libstdc++-v3/testsuite/performance/27_io/ifstream_getline-2.cc new file mode 100644 index 000000000..8c9ebd362 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ifstream_getline-2.cc @@ -0,0 +1,93 @@ +// Copyright (C) 2004, 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/>. + + +#include <cstdio> +#include <fstream> +#include <string> +#include <testsuite_performance.h> + +// libstdc++/15002 +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const char filename[] = "tmp_getline.txt"; + const unsigned lines = 1000000; + const unsigned line_length = 200; + + char* line = new char[line_length + 2]; + + // Construct data. + { + memset(line, 'x', line_length); + line[line_length] = '\n'; + line[line_length + 1] = '\0'; + + ofstream out(filename); + for (unsigned i = 0; i < lines; ++i) + out << line; + } + + // C + { + // Fill the cache. + FILE *file = fopen(filename, "r"); + while (fgets(line, line_length + 2, file)); + fclose(file); + + file = fopen(filename, "r"); + start_counters(time, resource); + while (fgets(line, line_length + 2, file)); + stop_counters(time, resource); + fclose(file); + report_performance(__FILE__, "C (fgets)", time, resource); + clear_counters(time, resource); + } + + // getline(basic_istream<_CharT, _Traits>& __in, + // basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) + { + ifstream file(filename); + string string_line; + + start_counters(time, resource); + while (getline(file, string_line)); + stop_counters(time, resource); + report_performance(__FILE__, "C++ (string)", time, resource); + clear_counters(time, resource); + } + + // getline(char_type* __s, streamsize __n, char_type __delim) + { + ifstream file(filename); + + start_counters(time, resource); + while (file.getline(line, line_length + 2)); + stop_counters(time, resource); + report_performance(__FILE__, "C++ (char array)", time, resource); + clear_counters(time, resource); + } + + delete[] line; + unlink(filename); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ifstream_getline.cc b/libstdc++-v3/testsuite/performance/27_io/ifstream_getline.cc new file mode 100644 index 000000000..cda715060 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ifstream_getline.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2007, 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/>. + + +#include <fstream> +#include <cstdlib> +#include <testsuite_performance.h> + +// libstdc++/5001 (100,000 line input file) +int main () +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const char* name1 = "/usr/share/dict/words"; + const char* name2 = "/usr/share/dict/linux.words"; + ifstream in; + in.open(name1); + if (!in.is_open()) + { + in.clear(); + in.open(name2); + } + if (!in.is_open()) + exit(1); + + char buffer[BUFSIZ]; + start_counters(time, resource); + while (in.good()) + in.getline(buffer, BUFSIZ); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_float.cc b/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_float.cc new file mode 100644 index 000000000..203550db1 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_float.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2003, 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/>. + + +#include <fstream> +#include <sstream> +#include <testsuite_performance.h> + +// Based on libstdc++/8761 poor fstream performance (converted to float) +void test_insertion(int p = 6) +{ + using namespace std; + using namespace __gnu_test; + + const char* filename = "tmp_perf_float.txt"; + const int iterations = 10000000; + + ostringstream oss; + oss << "precision " << p; + + { + time_counter time; + resource_counter resource; + + ofstream out(filename); + out.precision(p); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + { + float f = i * 3.14159265358979323846; + out << f << '\n'; + } + stop_counters(time, resource); + report_performance(__FILE__, oss.str(), time, resource); + } + + unlink(filename); +}; + +int main() +{ + test_insertion(6); + test_insertion(12); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_int.cc b/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_int.cc new file mode 100644 index 000000000..22ac7982e --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/ofstream_insert_int.cc @@ -0,0 +1,41 @@ +// Copyright (C) 2003, 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/>. + + +#include <fstream> +#include <testsuite_performance.h> + +// libstdc++/8761 poor fstream performance +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 10000000; + + ofstream out("tmp_perf_int.txt"); + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + out << i << "\n"; + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + unlink("tmp_perf_int.txt"); + 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 000000000..86eb7d1d2 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/27_io/stringbuf_overflow.cc @@ -0,0 +1,51 @@ +// Copyright (C) 2004, 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/>. + + +#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; +} |