diff options
Diffstat (limited to 'libstdc++-v3/testsuite/performance')
84 files changed, 6497 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/performance/21_strings/append-1.cc b/libstdc++-v3/testsuite/performance/21_strings/append-1.cc new file mode 100644 index 000000000..60a9a8654 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/append-1.cc @@ -0,0 +1,77 @@ + // 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 <ctime> +#include <iostream> +#include <string> +#include <testsuite_performance.h> + +using namespace std; + +void +test_append_char(int how_much) +{ + string buf; // no preallocation + for (int i = 0; i < how_much; ++i) + buf.append(static_cast<string::size_type>(1) , 'x'); +} + +void +test_append_string(int how_much) +{ + string s(static_cast<string::size_type>(1) , 'x'); + string buf; // no preallocation + for (int i = 0; i < how_much; ++i) + buf.append(s); +} + +void +run_benchmark1(int how_much) +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + start_counters(time, resource); + test_append_char(how_much); + stop_counters(time, resource); + report_performance(__FILE__, "char", time, resource); +} + +void +run_benchmark2(int how_much) +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + start_counters(time, resource); + test_append_string(how_much); + stop_counters(time, resource); + report_performance(__FILE__, "string", time, resource); +} + +// libstdc++/5380 +// libstdc++/4960 +int main() +{ + run_benchmark1(100000); + run_benchmark2(100000); + run_benchmark1(1000000); + run_benchmark2(1000000); + run_benchmark1(10000000); + run_benchmark2(10000000); +} diff --git a/libstdc++-v3/testsuite/performance/21_strings/append-2.cc b/libstdc++-v3/testsuite/performance/21_strings/append-2.cc new file mode 100644 index 000000000..8c44cb0f0 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/append-2.cc @@ -0,0 +1,46 @@ +// 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 <string> +#include <testsuite_performance.h> + +// Short strings didn't grow quickly... +void test01() +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + start_counters(time, resource); + for (unsigned i = 0; i < 200000; ++i) + { + std::string a; + for (unsigned j = 0; j < 400; ++j) + a.append(1, 'x'); + } + stop_counters(time, resource); + + report_performance(__FILE__, "", time, resource); + clear_counters(time, resource); +} + +int main() +{ + test01(); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/21_strings/cons_input_iterator.cc b/libstdc++-v3/testsuite/performance/21_strings/cons_input_iterator.cc new file mode 100644 index 000000000..fcf3eb893 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/cons_input_iterator.cc @@ -0,0 +1,49 @@ +// 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 <iterator> +#include <sstream> + +#include <testsuite_performance.h> + +void benchmark(long len) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + istringstream isstr(string(len, 'a')); + + start_counters(time, resource); + string str((istreambuf_iterator<char>(isstr)), + istreambuf_iterator<char>()); + stop_counters(time, resource); + + report_performance(__FILE__, "", time, resource); + clear_counters(time, resource); +} + +int main() +{ + benchmark(500000); + benchmark(5000000); + benchmark(50000000); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/21_strings/copy_cons_and_dest.cc b/libstdc++-v3/testsuite/performance/21_strings/copy_cons_and_dest.cc new file mode 100644 index 000000000..1ec18d3e4 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/copy_cons_and_dest.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <string> +#include <testsuite_performance.h> + +void benchmark(long len) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + start_counters(time, resource); + string a("1"); + for (long i = 0; i < len; ++i) + { + string ss1(a); + string ss2(ss1); + string ss3(ss2); + string ss4(ss3); + string ss5(ss4); + } + stop_counters(time, resource); + + report_performance(__FILE__, "", time, resource); + clear_counters(time, resource); +} + +int main() +{ + benchmark(1000000); + benchmark(10000000); + benchmark(100000000); + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/21_strings/find.cc b/libstdc++-v3/testsuite/performance/21_strings/find.cc new file mode 100644 index 000000000..eeda0802b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/find.cc @@ -0,0 +1,96 @@ + // 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 <string> +#include <testsuite_performance.h> + +void +test_pair(const std::string& s, const std::string& f, int n) +{ + std::string::size_type sz = 0; + + for (int i = 0; i < n; ++i) + sz = s.find(f); +} + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const unsigned int iterations = 2000000; + + string s, f; + s = "aabbaabbaaxd adbffdadgaxaabbbddhatyaaaabbbaabbaabbcsy"; + f = "aabbaabbc"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "1", time, resource); + clear_counters(time, resource); + + f = "aabbb"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "2", time, resource); + clear_counters(time, resource); + + f = "xd"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "3", time, resource); + clear_counters(time, resource); + + s = "dhruv is a very very good boy ;-)"; + f = "very"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "4", time, resource); + clear_counters(time, resource); + + f = "bad"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "5", time, resource); + clear_counters(time, resource); + + f = "extra irritating"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "6", time, resource); + clear_counters(time, resource); + + s = "this is a very this is a very this is a verty this is a very " + "this is a very long sentence"; + f = "this is a very long sentence"; + start_counters(time, resource); + test_pair(s, f, iterations); + stop_counters(time, resource); + report_performance(__FILE__, "7", time, resource); + clear_counters(time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/21_strings/hash.cc b/libstdc++-v3/testsuite/performance/21_strings/hash.cc new file mode 100644 index 000000000..0c409c5da --- /dev/null +++ b/libstdc++-v3/testsuite/performance/21_strings/hash.cc @@ -0,0 +1,58 @@ +#include <string> +#include <vector> +#include <unordered_set> +#include <cstdlib> +#include <random> +#include <testsuite_performance.h> + +using namespace std; + +vector<string> +random_strings(int n, int len) +{ + string s(len, '\0'); + unordered_set<string> result_set; + random_device rd; + while (result_set.size() < n) + { + result_set.insert(s); + unsigned int tmp = rd(); + tmp %= len * 256; + s[tmp / 256] = tmp % 256; + } + return vector<string>(result_set.begin(), result_set.end()); +} + +int +main(int argc, char **argv) +{ + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + int string_size = 71; + int num_strings = 6000000; + if (argc > 1) + { + string_size = atoi(argv[1]); + if (argc > 2) + num_strings = atoi(argv[2]); + } + + // Construct random strings. + vector<string> v = random_strings(num_strings, string_size); + + // Time hashing. + size_t tmp = 0; // prevent compiler from optimizing away all the work + start_counters(time, resource); + for (int i = 0; i < num_strings; i++) + tmp += hash<string>()(v[i]); + stop_counters(time, resource); + + if (tmp != 0 || argc < 9) // use tmp to prevent compiler optimization + report_performance(__FILE__, "", time, resource); + + clear_counters(time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/is_wchar_t.cc b/libstdc++-v3/testsuite/performance/22_locale/is_wchar_t.cc new file mode 100644 index 000000000..6b845507e --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/is_wchar_t.cc @@ -0,0 +1,78 @@ +// 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 <locale> +#include <cwctype> +#include <cstddef> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const wchar_t str[] = + L"Is this the real life?\n" + L"Is this just fantasy?\n" + L"Caught in a landslide\n" + L"No escape from reality\n" + L"Open your eyes\n" + L"Look up to the skies and see\n" + L"I'm just a poor boy\n" + L"I need no sympathy\n" + L"Because I'm easy come, easy go\n" + L"Little high, little low" + L"Anyway the wind blows\n" + L"Doesn't really matter to me\n" + L"To me\n" + L" -- Queen\n"; + const size_t len = sizeof(str) / sizeof(str[0]) - 1; + + locale loc; + const ctype<wchar_t>& ct = use_facet<ctype<wchar_t> >(loc); + + // C + wctype_t w = wctype("space"); + start_counters(time, resource); + for (int j = 0; j < 200000; ++j) + { + for (size_t i = 0; i < len; ++i) + { + iswctype(str[i], w); + } + } + stop_counters(time, resource); + report_performance(__FILE__, "C", time, resource); + clear_counters(time, resource); + + // C++ + start_counters(time, resource); + for (int j = 0; j < 200000; ++j) + { + for (size_t i = 0; i < len; ++i) + { + ct.is(ctype_base::space, str[i]); + } + } + stop_counters(time, resource); + report_performance(__FILE__, "C++", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_char.cc b/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_char.cc new file mode 100644 index 000000000..44e28d6f9 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_char.cc @@ -0,0 +1,67 @@ +// 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 <locale> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + char bufin[] = "This was an attempt to bypass string construction just for test."; + char bufout[sizeof(bufin)]; + + locale loc; + const ctype<char>& ct = use_facet<ctype<char> >(loc); + + // narrow + start_counters(time, resource); + for (long i = 0; i < 1000000000; ++i) + ct.narrow(i % 128, '*'); + stop_counters(time, resource); + report_performance(__FILE__, "narrow", time, resource); + clear_counters(time, resource); + + // narrow array + start_counters(time, resource); + for (long i = 0; i < 100000000; ++i) + ct.narrow(bufin, bufin+sizeof(bufin), '*', bufout); + stop_counters(time, resource); + report_performance(__FILE__, "narrow_array", time, resource); + clear_counters(time, resource); + + // widen + start_counters(time, resource); + for (long i = 0; i < 1000000000; ++i) + ct.widen(i % 128); + stop_counters(time, resource); + report_performance(__FILE__, "widen", time, resource); + clear_counters(time, resource); + + // widen array + start_counters(time, resource); + for (long i = 0; i < 100000000; ++i) + ct.widen(bufin, bufin+sizeof(bufin), bufout); + stop_counters(time, resource); + report_performance(__FILE__, "widen_array", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_wchar_t.cc b/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_wchar_t.cc new file mode 100644 index 000000000..decd131d6 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/narrow_widen_wchar_t.cc @@ -0,0 +1,67 @@ +// 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 <locale> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + wchar_t bufwc[] = L"Mi innamoravo di tutto (Fabrizio De Andre')"; + char bufc[sizeof(bufwc) / sizeof(wchar_t)]; + + locale loc; + const ctype<wchar_t>& ct = use_facet<ctype<wchar_t> >(loc); + + // narrow + start_counters(time, resource); + for (long i = 0; i < 200000000; ++i) + ct.narrow(i % 128, '*'); + stop_counters(time, resource); + report_performance(__FILE__, "narrow", time, resource); + clear_counters(time, resource); + + // narrow array + start_counters(time, resource); + for (long i = 0; i < 20000000; ++i) + ct.narrow(bufwc, bufwc + sizeof(bufwc) / sizeof(wchar_t), '*', bufc); + stop_counters(time, resource); + report_performance(__FILE__, "narrow array", time, resource); + clear_counters(time, resource); + + // widen + start_counters(time, resource); + for (long i = 0; i < 200000000; ++i) + ct.widen(i % 128); + stop_counters(time, resource); + report_performance(__FILE__, "widen", time, resource); + clear_counters(time, resource); + + // widen array + start_counters(time, resource); + for (long i = 0; i < 20000000; ++i) + ct.widen(bufc, bufc + sizeof(bufc), bufwc); + stop_counters(time, resource); + report_performance(__FILE__, "widen array", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/wchar_t_in.cc b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_in.cc new file mode 100644 index 000000000..021db4eab --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_in.cc @@ -0,0 +1,75 @@ +// 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 <cstring> +#include <fstream> +#include <langinfo.h> +#include <iconv.h> +#include <testsuite_performance.h> + +// libstdc++/11602 (do_in) +int main(int argc, char** argv) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iters = 400000; + + wchar_t wbuf[1024]; + char cbuf[1024]; + + memset(cbuf, 'a', 1024); + + // C (iconv) + iconv_t cd = iconv_open("WCHAR_T", nl_langinfo(CODESET)); + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + size_t inbytesleft = 1024; + size_t outbytesleft = 1024 * sizeof(wchar_t); + char* in = cbuf; + char* out = reinterpret_cast<char*>(wbuf); + iconv(cd, &in, &inbytesleft, &out, &outbytesleft); + } + stop_counters(time, resource); + iconv_close(cd); + report_performance(__FILE__, "C (iconv)", time, resource); + clear_counters(time, resource); + + // C++ (codecvt) + locale loc; + const codecvt<wchar_t, char, mbstate_t>& cvt = + use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); + mbstate_t state; + memset(&state, 0, sizeof(state)); + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + const char* from_next; + wchar_t* to_next; + cvt.in(state, cbuf, cbuf + 1024, from_next, + wbuf, wbuf + 1024, to_next); + } + stop_counters(time, resource); + report_performance(__FILE__, "C++ (codecvt)", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/wchar_t_length.cc b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_length.cc new file mode 100644 index 000000000..9c7d6c544 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_length.cc @@ -0,0 +1,53 @@ +// 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 <cstring> +#include <fstream> +#include <langinfo.h> +#include <iconv.h> +#include <testsuite_performance.h> + +// libstdc++/11602 (do_length) +int main(int argc, char** argv) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iters = 400000; + + char cbuf[1024]; + + memset(cbuf, 'a', 1024); + + // C++ (codecvt) + locale loc; + const codecvt<wchar_t, char, mbstate_t>& cvt = + use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); + mbstate_t state; + memset(&state, 0, sizeof(state)); + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + cvt.length(state, cbuf, cbuf + 1024, 1024); + stop_counters(time, resource); + report_performance(__FILE__, "C++ (codecvt)", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/22_locale/wchar_t_out.cc b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_out.cc new file mode 100644 index 000000000..1528d3893 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/22_locale/wchar_t_out.cc @@ -0,0 +1,75 @@ +// 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 <cstring> +#include <fstream> +#include <langinfo.h> +#include <iconv.h> +#include <testsuite_performance.h> + +// libstdc++/11602 +int main(int argc, char** argv) +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iters = 300000; + + wchar_t wbuf[1024]; + char cbuf[1024]; + + wmemset(wbuf, L'a', 1024); + + // C (iconv) + iconv_t cd = iconv_open(nl_langinfo(CODESET), "WCHAR_T"); + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + size_t inbytesleft = 1024 * sizeof(wchar_t); + size_t outbytesleft = 1024; + char* in = reinterpret_cast<char*>(wbuf); + char* out = cbuf; + iconv(cd, &in, &inbytesleft, &out, &outbytesleft); + } + stop_counters(time, resource); + iconv_close(cd); + report_performance(__FILE__, "C (iconv)", time, resource); + clear_counters(time, resource); + + // C++ (codecvt) + locale loc; + const codecvt<wchar_t, char, mbstate_t>& cvt = + use_facet<codecvt<wchar_t, char, mbstate_t> >(loc); + mbstate_t state; + memset(&state, 0, sizeof(state)); + start_counters(time, resource); + for (int i = 0; i < iters; ++i) + { + const wchar_t* from_next; + char* to_next; + cvt.out(state, wbuf, wbuf + 1024, from_next, + cbuf, cbuf + 1024, to_next); + } + stop_counters(time, resource); + report_performance(__FILE__, "C++ (codecvt)", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/copy_construct/vector_bool.cc b/libstdc++-v3/testsuite/performance/23_containers/copy_construct/vector_bool.cc new file mode 100644 index 000000000..96e13ba33 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/copy_construct/vector_bool.cc @@ -0,0 +1,38 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <vector> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + start_counters(time, resource); + const std::vector<bool> ref(100000); + + for (unsigned i = 0; i < 1000000; ++i) + std::vector<bool> v(ref); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/create/map.cc b/libstdc++-v3/testsuite/performance/23_containers/create/map.cc new file mode 100644 index 000000000..4527f2c21 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/create/map.cc @@ -0,0 +1,51 @@ +// 2003-03-01 gp dot bolton at computer dot org + +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + Container obj; + const int iterations = 250000; + for (int i = 0; i < iterations; ++i) + obj[i] = i; + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::maps<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("create"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc b/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc new file mode 100644 index 000000000..60911ca17 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/create_from_sorted/set.cc @@ -0,0 +1,61 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + typedef int test_type; + typedef Container container_type; + static const unsigned max_size = 250000; // avoid excessive swap file use! + static const unsigned iterations = 10; // make results less random while + static const unsigned step = 50000; // keeping the total time reasonable + + std::vector<test_type> v(max_size, 0); + for (test_type i = 0; i != max_size; ++i) + v[i] = i; // initialize sorted array + + for (test_type count = step; count <= max_size; count += step) + { + // Measure set construction time (linear in count (Table 69)) + for (test_type i = 0; i != iterations; ++i) + container_type(v.begin(), v.begin() + count); + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::sets<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("create_from_sorted"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc b/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc new file mode 100644 index 000000000..d8b3b51bd --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/create_sort/list.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + typedef Container container_type; + container_type obj; + const int iterations = 1000000; + for (unsigned int n = 1; n <= iterations; n *= 10) + { + for (unsigned int i = 0; i < n; ++i) + obj.push_back(n - i); + } + obj.sort(); + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::lists<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("create_sort"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/find/map.cc b/libstdc++-v3/testsuite/performance/23_containers/find/map.cc new file mode 100644 index 000000000..f206c2534 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/find/map.cc @@ -0,0 +1,57 @@ +// Copyright (C) 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// 2004-03-11 Dhruv Matani <dhruvbird@HotPOP.com> + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + Container obj; + int x = 2; + while (x--) + { + for (int i = 0; i < 300000; ++i) + obj.insert(std::make_pair(rand()%1000000, i)); + for (int i = 0; i < 100000; ++i) + obj.insert(std::make_pair(rand()%2000000, i)); + obj.clear(); + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::maps<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("find"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/index/map.cc b/libstdc++-v3/testsuite/performance/23_containers/index/map.cc new file mode 100644 index 000000000..0dad47523 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/index/map.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +// libstdc++/13823 recast for this testing framework +template<typename Container, int Iter> + void + do_loop() + { + try + { + Container obj; + for (int c = 0; c < 100; c++) + { + for (unsigned i = 0; i < Iter; ++i) + obj[i] = i; + } + } + catch(...) + { + // No point allocating all available memory, repeatedly. + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::maps<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("index_associative"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc new file mode 100644 index 000000000..c1ecc7f5f --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/associative.cc @@ -0,0 +1,63 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + Container obj; // XXX + int insert_values = 128; // XXX + + int test_iterations = 0; + + // XXX + // typedef typename Container::value_type test_type; + typedef int test_type; + + value_type<test_type> test_value; + while (test_iterations < Iter) + { + for (int j = 0; j < insert_values; ++j) + obj.insert(++test_value); + ++test_iterations; + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + using __gnu_test::associative_containers; + typedef associative_containers<int, thread_type>::type container_types; + + typedef test_sequence<thread_type> test_type; + test_type test("insert_associative"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc new file mode 100644 index 000000000..9673992a0 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/sequence.cc @@ -0,0 +1,59 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + Container obj; // XXX + int insert_values = 128; // XXX + + int test_iterations = 0; + typedef typename Container::value_type test_type; + value_type<test_type> test_value; + while (test_iterations < Iter) + { + for (int j = 0; j < insert_values; ++j) + obj.insert(obj.end(), ++test_value); + ++test_iterations; + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + using __gnu_test::sequence_containers; + typedef sequence_containers<int, thread_type>::type container_types; + + typedef test_sequence<thread_type> test_type; + test_type test("insert_sequence"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert/unordered_map_array.cc b/libstdc++-v3/testsuite/performance/23_containers/insert/unordered_map_array.cc new file mode 100644 index 000000000..2cc22d1d2 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert/unordered_map_array.cc @@ -0,0 +1,52 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <tr1/unordered_map> +#include <testsuite_performance.h> + +typedef std::tr1::unordered_map<int, int> map_type; +typedef std::tr1::unordered_map<int, map_type> matrix_type; + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const int sz = 1000; + + matrix_type matrix; + + start_counters(time, resource); + for (int iter = 0; iter < 50; ++iter) + { + for (int i = 0; i < sz; ++i) + { + for (int j = 0; j < sz; ++j) + { + map_type& row = matrix[i / 4]; + ++row[j / 4]; + } + } + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc new file mode 100644 index 000000000..a310f8ed6 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert_erase/associative.cc @@ -0,0 +1,66 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + // XXX + // typedef typename Container::value_type test_type; + typedef int test_type; + value_type<test_type> test_value; + + const int insert_values = 128; // XXX + Container obj; // XXX + for (int i = 0; i < Iter; ++i) + { + for (int j = 0; j < insert_values; ++j) + obj.insert(++test_value); + } + + const int erasei = static_cast<int>(Iter / 4); + for (int i = 0; i < erasei; ++i) + { + int key = i * 2; + obj.erase(key); + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + using __gnu_test::associative_containers; + typedef associative_containers<int, thread_type>::type container_types; + + typedef test_sequence<thread_type> test_type; + test_type test("insert_erase_associative"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc b/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc new file mode 100644 index 000000000..2e94dcac7 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc @@ -0,0 +1,77 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + // avoid excessive swap file use! + static const unsigned max_size = 250000; + + // make results less random while + static const unsigned iterations = 10; + + // keeping the total time reasonable + static const unsigned step = 50000; + + using namespace std; + typedef int test_type; + typedef Container container_type; + typedef vector<test_type> vector_type; + + // Initialize sorted array. + vector_type v(max_size, 0); + for (unsigned int i = 0; i != max_size; ++i) + v[i] = i; + + for (unsigned int count = step; count <= max_size; count += step) + { + for (unsigned i = 0; i != iterations; ++i) + { + container_type test_set; + typename container_type::iterator iter = test_set.end(); + + // Each insert in amortized constant time (Table 69) + for (unsigned j = 0; j != count; ++j) + iter = test_set.insert(iter, v[j]); + } + } + + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::sets<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("insert_from_sorted"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc new file mode 100644 index 000000000..0db964e59 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/associative.cc @@ -0,0 +1,248 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +typedef int test_type; + +// The number of iterations to be performed. +int iterations = 1000; + +// TODO - restore Stefan's comment? i don't understand it. -- fwy +int insert_values = 128; + +class Lock +{ +public: + Lock() {pthread_mutex_init(&mutex, 0);} + ~Lock() {pthread_mutex_destroy(&mutex);} + +public: + inline pthread_mutex_t* operator&() {return &mutex;} + +public: + inline void lock() {pthread_mutex_lock(&mutex);} + inline void unlock() {pthread_mutex_unlock(&mutex);} + +private: + Lock(const Lock&); + Lock& operator=(Lock&); + +private: + pthread_mutex_t mutex; +}; + +class AutoLock +{ +public: + AutoLock(Lock& _lock) + : lock(_lock) + {lock.lock();} + + ~AutoLock() {lock.unlock();} + +private: + AutoLock(AutoLock&); + AutoLock& operator=(AutoLock&); + +private: + Lock& lock; +}; + +template<typename Container> + class Queue + { + public: + Queue() {pthread_cond_init(&condition, 0);} + ~Queue() {pthread_cond_destroy(&condition);} + + public: + void push_back(const typename Container::value_type& x); + void swap(Container& container); + + private: + pthread_cond_t condition; + Lock lock; + Container queue; + }; + +template<typename Container> + void + Queue<Container>::push_back(const typename Container::value_type& value) + { + AutoLock auto_lock(lock); + const bool signal = queue.empty(); + queue.insert(queue.end(), value); + if (signal) pthread_cond_signal(&condition); + } + +template<typename Container> + void + Queue<Container>::swap(Container& container) + { + AutoLock auto_lock(lock); + while (queue.empty()) pthread_cond_wait(&condition, &lock); + queue.swap(container); + } + +class Thread +{ + // NB: Make this the last data member of an object defining operator()(). +public: + class Attributes + { + public: + Attributes(int state = PTHREAD_CREATE_JOINABLE); + ~Attributes() {pthread_attr_destroy(&attributes);} + + public: + inline pthread_attr_t* operator&() {return &attributes;} + + private: + pthread_attr_t attributes; + }; + +public: + Thread() {thread = pthread_self();} + ~Thread(); + +public: + template <typename ThreadOwner> + void create(ThreadOwner* owner); + +private: + pthread_t thread; +}; + +Thread::Attributes::Attributes(int state) +{ + pthread_attr_init(&attributes); + pthread_attr_setdetachstate(&attributes, state); +} + +Thread::~Thread() +{ + if (!pthread_equal(thread, pthread_self())) + pthread_join(thread, 0); +} + +template<typename ThreadOwner> + void* + create_thread(void* _this) + { + ThreadOwner* owner = static_cast<ThreadOwner*>(_this); + (*owner)(); + return 0; + } + +template<typename ThreadOwner> + void + Thread::create(ThreadOwner* owner) + { + Thread::Attributes attributes; + pthread_create(&thread, &attributes, create_thread<ThreadOwner>, owner); + } + +template<typename Container> + class Consumer + { + public: + Consumer(Queue<Container>& _queue) + : queue(_queue) + {thread.create(this);} + + public: + void operator()(); + + private: + Queue<Container>& queue; + Thread thread; + }; + +template<typename Container> + void + Consumer<Container>::operator()() + { + for (int j = insert_values * iterations; j > 0;) + { + Container container; + queue.swap(container); + j -= container.size(); + } + } + +template<typename TestType> + struct Value : public std::pair<TestType, TestType> + { + Value() + : std::pair<TestType, TestType>(0, 0) + { } + + inline Value operator++() {return ++this->first, *this;} + inline operator TestType() const {return this->first;} + }; + +template<typename Container> + class ProducerConsumer : private Queue<Container> + { + public: + ProducerConsumer() {thread.create(this);} + + public: + void operator()(); + + private: + Thread thread; + }; + +template<typename Container> + void + ProducerConsumer<Container>::operator()() + { + Consumer<Container> consumer(*this); + Value<test_type> test_value; + for (int j = insert_values * iterations; j-- > 0;) + this->push_back(++test_value); + } + +template<typename Container, int Iter> + void + do_loop() + { + ProducerConsumer<Container> pc1; + ProducerConsumer<Container> pc2; + } + +int +main() +{ +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::maps<test_type, thread_type>::type map_typelist; + typedef __gnu_test::sets<test_type, thread_type>::type set_typelist; + typedef __gnu_cxx::typelist::append<map_typelist, set_typelist>::type container_types; + + typedef test_sequence<thread_type> test_type; + test_type test("producer_consumer_associative"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc new file mode 100644 index 000000000..19118c952 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/producer_consumer/sequence.cc @@ -0,0 +1,247 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +typedef int test_type; + +// The number of iterations to be performed. +int iterations = 1000; + +// TODO - restore Stefan's comment? i don't understand it. -- fwy +int insert_values = 128; + +class Lock +{ +public: + Lock() {pthread_mutex_init(&mutex, 0);} + ~Lock() {pthread_mutex_destroy(&mutex);} + +public: + inline pthread_mutex_t* operator&() {return &mutex;} + +public: + inline void lock() {pthread_mutex_lock(&mutex);} + inline void unlock() {pthread_mutex_unlock(&mutex);} + +private: + Lock(const Lock&); + Lock& operator=(Lock&); + +private: + pthread_mutex_t mutex; +}; + +class AutoLock +{ +public: + AutoLock(Lock& _lock) + : lock(_lock) + {lock.lock();} + + ~AutoLock() {lock.unlock();} + +private: + AutoLock(AutoLock&); + AutoLock& operator=(AutoLock&); + +private: + Lock& lock; +}; + +template<typename Container> + class Queue + { + public: + Queue() {pthread_cond_init(&condition, 0);} + ~Queue() {pthread_cond_destroy(&condition);} + + public: + void push_back(const typename Container::value_type& x); + void swap(Container& container); + + private: + pthread_cond_t condition; + Lock lock; + Container queue; + }; + +template<typename Container> + void + Queue<Container>::push_back(const typename Container::value_type& value) + { + AutoLock auto_lock(lock); + const bool signal = queue.empty(); + queue.insert(queue.end(), value); + if (signal) pthread_cond_signal(&condition); + } + +template<typename Container> + void + Queue<Container>::swap(Container& container) + { + AutoLock auto_lock(lock); + while (queue.empty()) pthread_cond_wait(&condition, &lock); + queue.swap(container); + } + +class Thread +{ + // NB: Make this the last data member of an object defining operator()(). +public: + class Attributes + { + public: + Attributes(int state = PTHREAD_CREATE_JOINABLE); + ~Attributes() {pthread_attr_destroy(&attributes);} + + public: + inline pthread_attr_t* operator&() {return &attributes;} + + private: + pthread_attr_t attributes; + }; + +public: + Thread() {thread = pthread_self();} + ~Thread(); + +public: + template <typename ThreadOwner> + void create(ThreadOwner* owner); + +private: + pthread_t thread; +}; + +Thread::Attributes::Attributes(int state) +{ + pthread_attr_init(&attributes); + pthread_attr_setdetachstate(&attributes, state); +} + +Thread::~Thread() +{ + if (!pthread_equal(thread, pthread_self())) + pthread_join(thread, 0); +} + +template<typename ThreadOwner> + void* + create_thread(void* _this) + { + ThreadOwner* owner = static_cast<ThreadOwner*>(_this); + (*owner)(); + return 0; + } + +template<typename ThreadOwner> + void + Thread::create(ThreadOwner* owner) + { + Thread::Attributes attributes; + pthread_create(&thread, &attributes, create_thread<ThreadOwner>, owner); + } + +template<typename Container> + class Consumer + { + public: + Consumer(Queue<Container>& _queue) + : queue(_queue) + {thread.create(this);} + + public: + void operator()(); + + private: + Queue<Container>& queue; + Thread thread; + }; + +template<typename Container> + void + Consumer<Container>::operator()() + { + for (int j = insert_values * iterations; j > 0;) + { + Container container; + queue.swap(container); + j -= container.size(); + } + } + +template<typename TestType> + struct Value : public std::pair<TestType, TestType> + { + Value() + : std::pair<TestType, TestType>(0, 0) + { } + + inline Value operator++() {return ++this->first, *this;} + inline operator TestType() const {return this->first;} + }; + +template<typename Container> + class ProducerConsumer : private Queue<Container> + { + public: + ProducerConsumer() {thread.create(this);} + + public: + void operator()(); + + private: + Thread thread; + }; + +template<typename Container> + void + ProducerConsumer<Container>::operator()() + { + Consumer<Container> consumer(*this); + Value<test_type> test_value; + for (int j = insert_values * iterations; j-- > 0;) + this->push_back(++test_value); + } + +template<typename Container, int Iter> + void + do_loop() + { + ProducerConsumer<Container> pc1; + ProducerConsumer<Container> pc2; + } + +int +main() +{ +#ifdef TEST_T1 +#define thread_type true +#endif + + using __gnu_test::sequence_containers; + typedef sequence_containers<test_type, thread_type>::type container_types; + + typedef test_sequence<thread_type> test_type; + test_type test("producer_consumer_sequence"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/23_containers/range_construct/deque_construct.cc b/libstdc++-v3/testsuite/performance/23_containers/range_construct/deque_construct.cc new file mode 100644 index 000000000..c8a804ed2 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/range_construct/deque_construct.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2010 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/>. +// + +// Performance test of debug mode deque range constructor +#define _GLIBCXX_DEBUG + +#include <deque> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::deque<int> ref(50000, 3); + + start_counters(time, resource); + + for (unsigned i = 0; i < 1000; ++i) + std::deque<int> v(ref.begin(), ref.end()); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct1.cc b/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct1.cc new file mode 100644 index 000000000..19224ad2f --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct1.cc @@ -0,0 +1,44 @@ +// Copyright (C) 2010 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/>. +// + +// Performance test of debug mode list range constructor +#define _GLIBCXX_DEBUG + +#include <vector> +#include <list> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::vector<int> ref(50000, 3); + + start_counters(time, resource); + + for (unsigned i = 0; i < 1000; ++i) + std::list<int> l(ref.begin(), ref.end()); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct2.cc b/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct2.cc new file mode 100644 index 000000000..51bc7a17b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/range_construct/list_construct2.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2010 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/>. +// + +// Performance test of debug mode list range constructor +#define _GLIBCXX_DEBUG + +#include <list> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::list<int> ref(50000, 3); + + start_counters(time, resource); + + for (unsigned i = 0; i < 1000; ++i) + std::list<int> l(ref.begin(), ref.end()); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/range_construct/vector_construct.cc b/libstdc++-v3/testsuite/performance/23_containers/range_construct/vector_construct.cc new file mode 100644 index 000000000..08716a543 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/range_construct/vector_construct.cc @@ -0,0 +1,43 @@ +// Copyright (C) 2010 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/>. +// + +// Performance test of debug mode vector range constructor +#define _GLIBCXX_DEBUG + +#include <vector> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::vector<int> ref(50000, 3); + + start_counters(time, resource); + + for (unsigned i = 0; i < 1000; ++i) + std::vector<int> v(ref.begin(), ref.end()); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + 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 000000000..ac329a0ac --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/resize/vector_bool.cc @@ -0,0 +1,40 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <vector> +#include <testsuite_performance.h> + +// 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<bool> vec; + vec.resize(i); + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc b/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc new file mode 100644 index 000000000..72c5ed977 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/23_containers/sort_search/list.cc @@ -0,0 +1,72 @@ +// Copyright (C) 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <testsuite_performance.h> + +template<typename Container, int Iter> + void + do_loop() + { + // XXX + const int iter = 150000; + typedef Container container_type; + container_type obj; + int ctr = 3; + while (ctr--) + { + for (int i = 0; i < iter; ++i) + obj.push_back(rand()%500001); + + //Search for random values that may or may not belong to the list. + for (int i = 0; i < 50; ++i) + std::find(obj.begin(), obj.end(), rand() % 100001); + + obj.sort(); + + //Search for random values that may or may not belong to the list. + for (int i = 0; i < 50; ++i) + { + typedef typename container_type::iterator iterator_type; + iterator_type _liter = std::find(obj.begin(), obj.end(), + rand() % 100001); + if (_liter != obj.end()) + obj.erase(_liter); + } + obj.clear(); + } + } + +int +main() +{ +#ifdef TEST_S1 +#define thread_type false +#endif + +#ifdef TEST_T1 +#define thread_type true +#endif + + typedef __gnu_test::lists<int, thread_type>::type container_types; + typedef test_sequence<thread_type> test_type; + test_type test("sort_search"); + __gnu_cxx::typelist::apply(test, container_types()); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc new file mode 100644 index 000000000..461dfc044 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/copy_backward_deque_iterators.cc @@ -0,0 +1,40 @@ +// 2009-24-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::deque<int> data(3000, 3); + + 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::copy_backward(data.begin(), data.begin() + j, d.end()); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc new file mode 100644 index 000000000..35d5d79de --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/copy_deque_iterators.cc @@ -0,0 +1,40 @@ +// 2009-23-12 Paolo Carlini <paolo.carlini@oracle.com> +// +// 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 <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const std::deque<int> data(3000, 3); + + 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::copy(data.begin(), data.begin() + j, d.begin()); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc new file mode 100644 index 000000000..6f22f69c3 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/copy_streambuf_iterators.cc @@ -0,0 +1,98 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_performance.h> + +// libstdc++/25482 +int main() +{ + using namespace std; + using namespace __gnu_test; + + typedef istreambuf_iterator<char> in_iterator_type; + typedef ostreambuf_iterator<char> out_iterator_type; + + time_counter time; + resource_counter resource; + + const char data[] = "Contrappunto dialettico alla mente"; + + // istreambuf iterators -> ostreambuf iterator + { + istringstream iss(data); + in_iterator_type beg(iss); + in_iterator_type end; + + ostringstream oss; + out_iterator_type out(oss); + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + iss.seekg(0); + oss.seekp(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "isb iters -> osb iter", time, resource); + clear_counters(time, resource); + } + + // char array -> ostreambuf iterator + { + const char* beg = data; + const char* end = data + sizeof(data) - 1; + + ostringstream oss; + out_iterator_type out(oss); + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + oss.seekp(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "pointers -> osb iter", time, resource); + clear_counters(time, resource); + } + + // istreambuf iterators -> char array + { + istringstream iss(data); + in_iterator_type beg(iss); + in_iterator_type end; + + char out[sizeof(data)]; + + start_counters(time, resource); + for (unsigned i = 0; i < 10000000; ++i) + { + copy(beg, end, out); + iss.seekg(0); + } + stop_counters(time, resource); + report_performance(__FILE__, "isb iters -> pointer", time, resource); + clear_counters(time, resource); + } + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc b/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc new file mode 100644 index 000000000..8ed9a39c6 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/find_istreambuf_iterators.cc @@ -0,0 +1,54 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <iterator> +#include <sstream> +#include <algorithm> +#include <testsuite_performance.h> + +// libstdc++/25482 +int main() +{ + using namespace std; + using namespace __gnu_test; + + typedef istreambuf_iterator<char> in_iterator_type; + + istringstream iss("a0000b1111c2222d3333e4444f5555g6666h7777i8888j9999" + "k0000l1111m2222n3333o4444p5555q6666r7777s8888t9999"); + + in_iterator_type beg(iss); + in_iterator_type end; + + time_counter time; + resource_counter resource; + + start_counters(time, resource); + for (unsigned i = 0; i < 1000000; ++i) + { + for (char c = 'a'; c < 'u'; ++c) + { + find(beg, end, c); + iss.seekg(0); + } + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/lexicographical_compare.cc b/libstdc++-v3/testsuite/performance/25_algorithms/lexicographical_compare.cc new file mode 100644 index 000000000..8bab57e27 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/lexicographical_compare.cc @@ -0,0 +1,46 @@ +// Copyright (C) 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 <vector> +#include <testsuite_performance.h> + +// libstdc++/32908 +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + int cnt = 0; + std::vector<int> a(10000), b(10000); + + start_counters(time, resource); + for (int i = 0; i < 100000; ++i) + { + if (a < b) + ++cnt; + if (a > b) + ++cnt; + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + clear_counters(time, resource); + + return cnt; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/nth_element_worst_case.cc b/libstdc++-v3/testsuite/performance/25_algorithms/nth_element_worst_case.cc new file mode 100644 index 000000000..a405f9ea9 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/nth_element_worst_case.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <vector> +#include <algorithm> +#include <testsuite_performance.h> + +int main() +{ + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + const int max_size = 8192; + + std::vector<int> v[max_size]; + + for (int i = 0; i < max_size; ++i) + { + for (int j = 0; j < i; j += 4) + { + v[i].push_back(j / 2); + v[i].push_back((i - 2) - (j / 2)); + } + + for (int j = 1; j < i; j += 2) + v[i].push_back(j); + } + + start_counters(time, resource); + for (int i = 0; i < max_size; ++i) + std::nth_element(v[i].begin(), v[i].begin() + i, v[i].end()); + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc b/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc new file mode 100644 index 000000000..13bc6ad9f --- /dev/null +++ b/libstdc++-v3/testsuite/performance/25_algorithms/search_n.cc @@ -0,0 +1,63 @@ +// 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/>. + + +#define DISABLE_ITERATOR_DEBUG 1 + +#include<cstdlib> +#include<vector> +#include<algorithm> + +#include<sstream> +#include<testsuite_performance.h> +#include<testsuite_iterators.h> + +using namespace std; +using namespace __gnu_test; + +const int length = 10000000; +const int match_length = 3; +int array[length]; + +int +main(void) +{ + time_counter time; + resource_counter resource; + int match = rand() % (match_length - 1); + for(int i = 0; i < length; i++) + { + array[i] = (match != 0) ? 1 : 0; + if(--match < 0) match = rand() % (match_length - 1); + } + __gnu_test::test_container<int, forward_iterator_wrapper> fcon(array, array + length); + start_counters(time, resource); + for(int i = 0; i < 100; i++) + search_n(fcon.begin(), fcon.end(), 10, 1); + stop_counters(time, resource); + report_performance(__FILE__, "forward iterator", time, resource); + clear_counters(time, resource); + + __gnu_test::test_container<int, random_access_iterator_wrapper> rcon(array, array + length); + start_counters(time, resource); + for(int i = 0; i < 100; i++) + search_n(rcon.begin(), rcon.end(), 10, 1); + stop_counters(time, resource); + report_performance(__FILE__, "random acess iterator", time, resource); + clear_counters(time, resource); +} + diff --git a/libstdc++-v3/testsuite/performance/26_numerics/complex_norm.cc b/libstdc++-v3/testsuite/performance/26_numerics/complex_norm.cc new file mode 100644 index 000000000..428959dc1 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/26_numerics/complex_norm.cc @@ -0,0 +1,74 @@ +// 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 <complex> +#include <testsuite_performance.h> + +// based on libstdc++/5730, use --fast-math +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + const int iterations = 2000; + + typedef complex<double> complex_type; + complex_type u[2048]; + + for (int i = 0; i < 2048; ++i) + u[i] = 1.0; + + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + { + complex_type * p = u; + for (int j = 0; j < 2048; ++j) + { + double u2 = norm(*p); + double t = u2 * 0.1; + *p *= complex_type(cos(t), sin(t)); + ++p; + } + } + stop_counters(time, resource); + report_performance(__FILE__, "norm", time, resource); + clear_counters(time, resource); + + start_counters(time, resource); + for (int i = 0; i < iterations; ++i) + { + complex_type * p = u; + for (int j = 0; j < 2048; ++j) + { + // Shouldn't be slower than the above. + double ur = real(*p); + double ui = imag(*p); + double u2 = ur * ur + ui * ui; + double t = u2 * 0.1; + *p *= complex_type(cos(t), sin(t)); + ++p; + } + } + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} + diff --git a/libstdc++-v3/testsuite/performance/26_numerics/valarray_gslice_to_index.cc b/libstdc++-v3/testsuite/performance/26_numerics/valarray_gslice_to_index.cc new file mode 100644 index 000000000..405d5c355 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/26_numerics/valarray_gslice_to_index.cc @@ -0,0 +1,48 @@ +// Copyright (C) 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +#include <valarray> +#include <testsuite_performance.h> + +int main() +{ + using namespace std; + using namespace __gnu_test; + + time_counter time; + resource_counter resource; + + valarray<double> va(1000000); + + for (int i = 0; i < 1000000; ++i) + va[i] = i; + + size_t lengthvalues[] = { 10, 10, 10, 10, 10, 10 }; + size_t stridevalues[] = { 1, 1, 1, 1, 1, 1 }; + + valarray<size_t> lengths(lengthvalues, 6); + valarray<size_t> stride(stridevalues, 6); + + start_counters(time, resource); + for (int j = 0; j < 1000; ++j) + va[gslice(0, lengths, stride)]; + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} 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; +} diff --git a/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc new file mode 100644 index 000000000..83fde2710 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/30_threads/future/polling.cc @@ -0,0 +1,64 @@ +// Copyright (C) 2009, 2010 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 <future> +#include <thread> +#include <testsuite_performance.h> + +inline bool is_ready(std::shared_future<void>& f) +{ + return f.wait_for(std::chrono::microseconds(1)); +} + +void poll(std::shared_future<void> f) +{ + while (!is_ready(f)) + { } +} + +int main() +{ +#ifdef TEST_T1 +#define thread_type true +#endif + + using namespace __gnu_test; + time_counter time; + resource_counter resource; + + const int n = 20; + std::promise<void> p; + std::shared_future<void> f = p.get_future(); + std::thread pollers[n]; + for (int i=0; i < n; ++i) + pollers[i] = std::thread(poll, f); + + start_counters(time, resource); + + for (int i = 0; i < 1000000; ++i) + (void)is_ready(f); + p.set_value(); + + for (int i=0; i < n; ++i) + pollers[i].join(); + + stop_counters(time, resource); + report_performance(__FILE__, "", time, resource); + + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_random_int_erase_mem_usage.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_random_int_erase_mem_usage.cc new file mode 100644 index 000000000..e1c7d9ec8 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_random_int_erase_mem_usage.cc @@ -0,0 +1,118 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_random_int_erase_mem_usage_test.cpp + * Contains test for erasing random integers. + */ + +#include <ext/typelist.h> +#include <testsuite_allocator.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/mem_usage/erase_test.hpp> +#include <iostream> +#include <vector> +#include <functional> + +struct int_hash : public std::unary_function<int, int> +{ + inline int + operator()(int i) const + { return i; } +}; + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + try + { + xml_test_performance_formatter fmt("Size", "Memory (bytes)"); + + typedef std::vector<int> vec_t; + vec_t a_v(vm); + twister_rand_gen g; + for (size_t i = 0; i < vm; ++i) + a_v[i] = static_cast<int>(g.get_unsigned_long()); + + vec_t::const_iterator b = a_v.begin(); + erase_test<vec_t::const_iterator> tst(b, vn, vs, vm); + typedef __gnu_test::tracker_allocator<char> alloc_t; + { + typedef hash_common_types<int, __gnu_pbds::null_mapped_type, int_hash, std::equal_to<int>, alloc_t>::performance_tl tl_t; + + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_hash_set<int, 8, int_hash, std::equal_to<int>, std::less<int>, alloc_t> native_t; + + tst(native_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: hash_random_int_erase_if_test <vn> <vs> <vm>" + << endl << endl; + + cerr << "This test checks the performance of various associative containers " + "using their erase method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of random integers " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Erases all the elements, except one, from the constainer" + << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_zlob_random_int_find_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_zlob_random_int_find_timing.cc new file mode 100644 index 000000000..82abb640b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/hash_zlob_random_int_find_timing.cc @@ -0,0 +1,119 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file hash_zlob_random_int_find_timing_test.cpp + * Contains test for finding random integers. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_set.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/find_test.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<int, char> > vec_t; + vec_t a_v(vm); + twister_rand_gen g; + + for (size_t i = 0; i < vm; ++i) + { + int k = static_cast<int>(g.get_unsigned_long()); + a_v[i] = std::make_pair(k << 8, 0); + if ((a_v[i].first& 127) != 0) + throw std::logic_error("Fucked!"); + } + + vec_t::const_iterator b = a_v.begin(); + typedef find_test<vec_t::const_iterator> test_t; + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef native_hash_map<int, char> native_t; + tst(native_t()); + } + + { + typedef hash_common_types<int, char>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: hash_zlob_random_int_find_timing_test <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of zero low-order bit random integers " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Performs a sequence of find operations. At each iteration, " + "it finds, for each integer in the vector, its entry in the " + "container, using the find method"; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing.hpp b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing.hpp new file mode 100644 index 000000000..3b850840b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing.hpp @@ -0,0 +1,137 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file multimap_text_find_timing_test.cpp + * Contains test for inserting text words. + */ + +#include <ext/typelist.h> +#include <io/text_populate.hpp> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_multimap.hpp> +#include <native_type/native_multimap.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/multimap_find_test.hpp> +#include <performance/assoc/multimap_common_type.hpp> +#include <hash_fn/string_hash_fn.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +void +set_test_parameters(size_t& n, size_t&s, size_t& m, size_t& prm); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t prm; + size_t ratio_n; + size_t ratio_s; + size_t ratio_m; + + + set_test_parameters(prm, ratio_n, ratio_s, ratio_m); + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, int> > vec_t; + vec_t a_v_init(prm); + distinct_text_populate(f_name, a_v_init); + + vec_t a_v; + twister_rand_gen g; + for (size_t i = 0; i < ratio_m; ++i) + for (size_t j = 0; j < a_v_init.size(); ++j) + a_v.push_back(std::make_pair(a_v_init[j].first, + static_cast<int>(g.get_unsigned_long()))); + + vec_t::const_iterator b = a_v.begin(); + { + typedef mmap_tl_t<std::string, int, std::allocator<char> >::type mmap_tl_tl; + mmap_tl_tl tl; + + typedef multimap_find_test<vec_t::const_iterator, false> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_hash_multimap<std::string, int, 8, string_hash_fn> native_t; + typedef multimap_find_test<vec_t::const_iterator, true> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + tst(native_t()); + } + + { + typedef native_multimap<std::string, int> native_t; + typedef multimap_find_test<vec_t::const_iterator, true> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + tst(native_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: multimap_text_insert_test.out <prm> <ratio_n> <ratio_s> <ratio_m>" + << endl << endl; + + cerr << "This test checks the performance of various associative containers " + "using their insert method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of pairs of text words" << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Repeats the above test a number of times" << endl; + cerr << endl << endl; + + cerr << "prm = maximum size of distinct pair-first entries" << endl; + cerr << "ratio_n = minimum ratio of secondary keys to primary keys" << endl; + cerr << "ratio_s = step ratio of secondary keys to primary keys" << endl; + cerr << "ratio_m = maximum ratio of secondary keys to primary keys" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_large.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_large.cc new file mode 100644 index 000000000..b4b2179e9 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_large.cc @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_find_timing.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 100; + n = 3; + s = 4; + m = 20; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_small.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_small.cc new file mode 100644 index 000000000..75cfa8ed3 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_find_timing_small.cc @@ -0,0 +1,42 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_find_timing.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 400; + n = 1; + s = 1; + m = 6; +} + diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage.hpp b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage.hpp new file mode 100644 index 000000000..881960fc8 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage.hpp @@ -0,0 +1,155 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file multimap_text_insert_mem_usage_test.cpp + * Contains test for inserting text words. + */ + +#include <iostream> +#include <vector> +#include <ext/typelist.h> +#include <testsuite_allocator.h> +#include <io/text_populate.hpp> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_multimap.hpp> +#include <native_type/native_multimap.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/mem_usage/multimap_insert_test.hpp> +#include <performance/assoc/multimap_common_type.hpp> +#include <hash_fn/string_hash_fn.hpp> + +void +usage(); + +void +set_test_parameters(size_t& n, size_t&s, size_t& m, size_t& prm); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t prm; + size_t ratio_n; + size_t ratio_s; + size_t ratio_m; + + set_test_parameters(prm, ratio_n, ratio_s, ratio_m); + + try + { + xml_test_performance_formatter fmt("Size", "Memory (bytes)"); + + typedef std::vector<std::pair<std::string, int> > init_vec_t; + init_vec_t a_v_init(prm); + distinct_text_populate(f_name, a_v_init); + + typedef __gnu_test::tracker_allocator<char> alloc_t; + typedef std::basic_string<char, std::char_traits<char>, alloc_t> string_t; + typedef std::vector<std::pair<string_t, int> > vec_t; + vec_t a_v; + twister_rand_gen g; + for (size_t i = 0; i < ratio_m; ++i) + for (size_t j = 0; j < a_v_init.size(); ++j) + a_v.push_back(std::make_pair(string_t(a_v_init[j].first.begin(), a_v_init[j].first.end()), static_cast<int>(g.get_unsigned_long()))); + + vec_t::const_iterator b = a_v.begin(); + { + typedef mmap_tl_t<string_t, int, alloc_t>::type tl_t; + tl_t tl; + typedef multimap_insert_test<vec_t::const_iterator, false> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef mmap_tl_t< string_t, int, alloc_t>::type tl_t; + tl_t tl; + typedef multimap_insert_test<vec_t::const_iterator, false> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + __gnu_cxx::typelist::apply(tst, tl); + } + + typedef multimap_insert_test<vec_t::const_iterator, true> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + { + typedef native_multimap<string_t, int, std::less<string_t>, alloc_t> native_t; + tst(native_t()); + } + + { + typedef + native_hash_multimap< + string_t, + int, + 8, + string_hash_fn, std::equal_to<string_t>, + std::less<string_t>, + alloc_t> + native_t; + + tst(native_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: multimap_text_insert_test.out <prm> <ratio_n> <ratio_s> <ratio_m>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their insert method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of pairs of text words" << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "prm = maximum size of distinct pair-first entries" << endl; + cerr << "ratio_n = minimum ratio of secondary keys to primary keys" << endl; + cerr << "ratio_s = step ratio of secondary keys to primary keys" << endl; + cerr << "ratio_m = maximum ratio of secondary keys to primary keys" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_large.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_large.cc new file mode 100644 index 000000000..396864552 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_large.cc @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_insert_mem_usage.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 100; + n = 3; + s = 4; + m = 20; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_small.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_small.cc new file mode 100644 index 000000000..1dd88df6c --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_mem_usage_small.cc @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_insert_mem_usage.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 400; + n = 1; + s = 1; + m = 6; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing.hpp b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing.hpp new file mode 100644 index 000000000..79f081263 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing.hpp @@ -0,0 +1,137 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file multimap_text_insert_timing_test.cpp + * Contains test for inserting text words. + */ + +#include <ext/typelist.h> +#include <io/text_populate.hpp> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_multimap.hpp> +#include <native_type/native_multimap.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/multimap_insert_test.hpp> +#include <performance/assoc/multimap_common_type.hpp> +#include <hash_fn/string_hash_fn.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +void +set_test_parameters(size_t& n, size_t&s, size_t& m, size_t& prm); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t prm; + size_t ratio_n; + size_t ratio_s; + size_t ratio_m; + + set_test_parameters(prm, ratio_n, ratio_s, ratio_m); + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, int> > vec_t; + vec_t a_v_init(prm); + distinct_text_populate(f_name, a_v_init); + + vec_t a_v; + twister_rand_gen g; + for (size_t i = 0; i < ratio_m; ++i) + for (size_t j = 0; j < a_v_init.size(); ++j) + a_v.push_back(std::make_pair(a_v_init[j].first, + static_cast<int>(g.get_unsigned_long()))); + + vec_t::const_iterator b = a_v.begin(); + { + typedef mmap_tl_t<std::string, int, std::allocator<char> >::type mmap_tl_tl; + mmap_tl_tl tl; + typedef multimap_insert_test<vec_t::const_iterator, false> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_hash_multimap<std::string, int, 8, string_hash_fn> native_t; + typedef multimap_insert_test<vec_t::const_iterator, true> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + tst(native_t()); + } + + { + typedef native_multimap<std::string, int> native_t; + typedef multimap_insert_test<vec_t::const_iterator, true> test_type; + test_type tst(b, prm* ratio_n, prm* ratio_s, prm* ratio_m); + tst(native_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: multimap_text_insert_test.out <prm> <ratio_n> <ratio_s> <ratio_m>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their insert method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of pairs of text words" << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "prm = maximum size of distinct pair-first entries" << endl; + cerr << "ratio_n = minimum ratio of secondary keys to primary keys" << endl; + cerr << "ratio_s = step ratio of secondary keys to primary keys" << endl; + cerr << "ratio_m = maximum ratio of secondary keys to primary keys" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_large.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_large.cc new file mode 100644 index 000000000..70c3dafaf --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_large.cc @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_insert_timing.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 100; + n = 3; + s = 4; + m = 20; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_small.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_small.cc new file mode 100644 index 000000000..57deebb14 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/multimap_text_insert_timing_small.cc @@ -0,0 +1,41 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "multimap_text_insert_timing.hpp" + +void +set_test_parameters(size_t& prm, size_t&n, size_t& s, size_t& m) +{ + prm = 400; + n = 1; + s = 1; + m = 6; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_pop_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_pop_timing.cc new file mode 100644 index 000000000..6e59bdcd8 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_pop_timing.cc @@ -0,0 +1,118 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_random_int_push_pop_timing_test.cpp + * Contains test for finding random_int. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/push_pop_test.hpp> +#include <native_type/native_priority_queue.hpp> +#include <testsuite_rng.h> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<int, char> > vector_type; + vector_type a_v(vm); + twister_rand_gen g; + + for (size_t i = 0; i < vm; ++i) + a_v[i] = std::make_pair(static_cast<int>(g.get_unsigned_long()), 0); + vector_type::const_iterator b = a_v.begin(); + + typedef push_pop_test<vector_type::const_iterator> test_type; + test_type tst(b, vn, vs, vm); + { + typedef pq_common_types<int>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<int, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<int, false> native_pq_t; + tst(native_pq_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + std::cerr << "usage: priority_queue_random_int_push_pop_timing_test <vn> <vs> <vm>" << + std::endl << std::endl; + + std::cerr << + "This test checks the performance of various priority_queue containers " + "using their push and pop method. " << std::endl; + std::cerr << "Specifically, it does the following:" << std::endl; + std::cerr << "* Creates a vector of random integers " << std::endl; + std::cerr << "* Pushes the elements into the container" << std::endl; + std::cerr << "* Pops the elements from the container" << std::endl; + std::cerr << "* Repeats the above test a number of times " + << std::endl; + + std::cerr << std::endl << std::endl; + + std::cerr << "vn = minimum size of the vector" << std::endl; + std::cerr << "vs = step size of the vector" << std::endl; + std::cerr << "vm = maximum size of the vector" << std::endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_timing.cc new file mode 100644 index 000000000..5245521c8 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_random_int_push_timing.cc @@ -0,0 +1,116 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_random_int_push_timing_test.cpp + * Contains test for finding random_int. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/push_test.hpp> +#include <native_type/native_priority_queue.hpp> +#include <testsuite_rng.h> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<int, char> > vec_t; + vec_t a_v(vm); + twister_rand_gen g; + for (size_t i = 0; i < vm; ++i) + a_v[i] = std::make_pair(static_cast<int>(g.get_unsigned_long()), 0); + + typedef push_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef pq_common_types<int>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<int, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<int, false> native_pq_t; + tst(native_pq_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_random_int_push_timing_test <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various priority_queue containers " + "using their push method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of random integers " << endl; + cerr << "* Pushes the elements into the container" << endl; + cerr << "* Repeats the above test a number of times " + << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_join_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_join_timing.cc new file mode 100644 index 000000000..cad1d3596 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_join_timing.cc @@ -0,0 +1,113 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_text_join_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/join_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_priority_queue.hpp> +#include <iostream> +#include <vector> + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_text_join_timing_test <f_name> <vn> <vs> <vm>"; + cerr << endl << endl; + + cerr << "This test checks the performance of various priority_queueiative containers " + "using their join method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Pushes the elements into two containers" << endl; + cerr << "* Joins the two containers (and measures this time)" << endl; + cerr << "* Repeats the above test a number of times " << endl; + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef join_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef pq_common_types<std::string>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<std::string, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<std::string, false> native_pq_t; + tst(native_pq_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_down_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_down_timing.cc new file mode 100644 index 000000000..ce7f3ff49 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_down_timing.cc @@ -0,0 +1,37 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "priority_queue_text_modify_timing.hpp" + +void +set_test_parameters(bool& b) +{ b = false; } + diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_timing.hpp b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_timing.hpp new file mode 100644 index 000000000..8f31e11d9 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_timing.hpp @@ -0,0 +1,127 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_text_modify_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/modify_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_priority_queue.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +void +set_test_parameters(bool& b); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 100; + size_t vs = 100; + size_t vm = 1100; + bool modify_up; + + set_test_parameters(modify_up); + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef modify_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm, modify_up); + { + typedef pq_common_types<std::string>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<std::string, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<std::string, false> native_pq_t; + tst(native_pq_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_text_modify_timing_test <f_name> <vn> <vs> <vm> <modify_up>" << + endl << endl; + + cerr << + "This test checks the performance of various priority_queueiative containers " + "using their modify method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Pushes the elements into the container" << endl; + cerr << "* Modifies the words in the container. If modify_up == 't', then" << endl; + cerr << "* it modifies them to the largest word. If modify_up == 'f', then" << endl; + cerr << "* it modifies them to the smallest word." << endl; + cerr << "* Repeats the above test a number of times " + << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_up_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_up_timing.cc new file mode 100644 index 000000000..cf6e49993 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_modify_up_timing.cc @@ -0,0 +1,37 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +#include "priority_queue_text_modify_timing.hpp" + +void +set_test_parameters(bool& b) +{ b = true; } + diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem_usage.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem_usage.cc new file mode 100644 index 000000000..8c0181e98 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_pop_mem_usage.cc @@ -0,0 +1,119 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_text_push_pop_timing_test.cpp + * Contains test for finding text. + */ + +#include <iostream> +#include <vector> +#include <ext/typelist.h> +#include <testsuite_allocator.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/mem_usage/pop_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_priority_queue.hpp> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + try + { + xml_test_performance_formatter fmt("Size", "Memory (bytes)"); + typedef __gnu_test::tracker_allocator<char> callocator_type; + typedef __gnu_test::tracker_allocator<char> sallocator_type; + typedef std::basic_string<char, std::char_traits<char>, callocator_type> string_t; + + typedef std::vector<std::pair<string_t, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef pop_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef pq_common_types<string_t, std::less<string_t>, callocator_type>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<string_t, true, std::less<string_t>, sallocator_type> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<string_t, false, std::less<string_t>, sallocator_type> native_pq_t; + tst(native_pq_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_text_pop_mem_usage_test <f_name> <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various priority_queueiative containers " + "using their push method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Pushes the elements into the container, then pops until it's empty." << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_pop_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_pop_timing.cc new file mode 100644 index 000000000..a55a61e7b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_pop_timing.cc @@ -0,0 +1,116 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_text_push_pop_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/push_pop_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_priority_queue.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef push_pop_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef pq_common_types<std::string>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<std::string, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<std::string, false> native_pq_t; + tst(native_pq_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_text_push_pop_timing_test " + "<f_name> <vn> <vs> <vm>" << endl << endl; + + cerr << "This test checks the performance of various" + "priority_queue containers using their push method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Pushes the elements into the container, then pops until it's empty." << endl; + cerr << "* Repeats the above test a number of times) " + << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_timing.cc new file mode 100644 index 000000000..ca5ff6d2a --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/priority_queue_text_push_timing.cc @@ -0,0 +1,117 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file priority_queue_text_push_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/priority_queue/common_type.hpp> +#include <performance/priority_queue/timing/push_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_priority_queue.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef push_test<vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef pq_common_types<std::string>::performance_tl pq_tl_t; + pq_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_priority_queue<std::string, true> native_pq_t; + tst(native_pq_t()); + } + + { + typedef native_priority_queue<std::string, false> native_pq_t; + tst(native_pq_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: priority_queue_text_push_timing_test <f_name> <vn> <vs> <vm>" + << endl << endl; + + cerr << + "This test checks the performance of various priority_queue containers " + "using their push method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Pushes the elements into the container" << endl; + cerr << "* Repeats the above test a number of times " + << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_find_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_find_timing.cc new file mode 100644 index 000000000..cdf151051 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_find_timing.cc @@ -0,0 +1,126 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file random_int_find_timing_test.cpp + * Contains test for finding random integers. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_map.hpp> +#include <native_type/native_map.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/find_test.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector< std::pair< int, char> > vec_t; + vec_t a_v(vm); + twister_rand_gen g; + for (size_t i = 0; i < vm; ++i) + a_v[i] = std::make_pair(static_cast<int>(g.get_unsigned_long()), 0); + vec_t::const_iterator b = a_v.begin(); + + typedef find_test< vec_t::const_iterator> test_t; + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef native_hash_map< int, char> native_t; + tst(native_t()); + } + + { + typedef native_map< int, char> native_t; + tst(native_t()); + } + + { + typedef hash_common_types<int, char>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef tree_common_types<int, char>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: hash_random_int_find_timing_test <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of random integers " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Performs a sequence of find operations. At each iteration, " + "it finds, for each integer in the vector, its entry in the " + "container, using the find method"; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_find_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_find_timing.cc new file mode 100644 index 000000000..1680ff4ff --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_find_timing.cc @@ -0,0 +1,126 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file random_int_subscript_find_timing_test.cpp + * Contains test for subscripting random integers. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_map.hpp> +#include <native_type/native_map.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/subscript_find_test.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<int, size_t> > vec_t; + vec_t a_v(vm); + twister_rand_gen g; + for (size_t i = 0; i < vm; ++i) + a_v[i] = std::make_pair(static_cast<int>(g.get_unsigned_long()), 0); + vec_t::const_iterator b = a_v.begin(); + + typedef subscript_find_test<vec_t::const_iterator> test_t; + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef hash_common_types<int, size_t>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef tree_common_types<int, size_t>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_hash_map<int, size_t> native_t; + tst(native_t()); + } + + { + typedef native_map< int, size_t> native_t; + tst(native_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: hash_random_int_subscript_find_timing_test <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of random integers " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Performs a sequence of find operations. At each iteration, " + "it finds, for each integer in the vector, its entry in the " + "container, using the subscript operator"; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_insert_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_insert_timing.cc new file mode 100644 index 000000000..07d644e4f --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/random_int_subscript_insert_timing.cc @@ -0,0 +1,123 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file random_int_subscript_insert_timing_test.cpp + * Contains test for subscripting random integers. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <native_type/native_hash_map.hpp> +#include <native_type/native_map.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/subscript_insert_test.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<int, size_t> > vec_t; + vec_t a_v(vm); + twister_rand_gen g; + + for (size_t i = 0; i < vm; ++i) + a_v[i] = std::make_pair(static_cast<int>(g.get_unsigned_long()), 0); + vec_t::const_iterator b = a_v.begin(); + + typedef subscript_insert_test<vec_t::const_iterator> test_t; + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef hash_common_types<int, size_t>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef tree_common_types<int, size_t>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_hash_map< int, size_t> native_t; + tst(native_t()); + } + + { + typedef native_map< int, size_t> native_t; + tst(native_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: hash_random_int_subscript_insert_timing_test <vn> <vs> <vm>" + << endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of random integers " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/text_find_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/text_find_timing.cc new file mode 100644 index 000000000..b997a5ee9 --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/text_find_timing.cc @@ -0,0 +1,145 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file text_find_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/find_test.hpp> +#include <io/text_populate.hpp> +#include <hash_fn/string_hash_fn.hpp> +#include <native_type/native_hash_map.hpp> +#include <native_type/native_map.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + typedef std::vector<std::pair<std::string, char> > vec_t; + + vec_t a_v(vm); + text_populate(f_name, a_v); + typedef find_test<vec_t::const_iterator, false> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef trie_common_types<std::string, char>::performance_tl pat_trie_tl_t; + + typedef tree_common_types<std::string, char>::performance_tl tree_tl_t; + + typedef hash_common_types<std::string, char, string_hash_fn>::performance_tl hash_tl_t; + + typedef __gnu_cxx::typelist::append<pat_trie_tl_t, __gnu_cxx::typelist::append<hash_tl_t, tree_tl_t>::type>::type tl_t; + + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_map<std::string, char> native_map_t; + tst(native_map_t()); + +#ifdef PB_DS_USE_TR1 + typedef native_hash_map<std::string, char, 8, string_hash_fn> native_hash_map_t; + tst(native_hash_map_t()); + + typedef + native_hash_map< + std::string, + char, + 8, + string_hash_fn, + std::equal_to< + std::string>, + std::less< + std::string>, + std::allocator< + char>, + true> + sth_native_hash_map_t; + + tst(sth_native_hash_map_t()); +#endif + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: text_find_timing_test <f_name> <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Performs a sequence of find operations. At each iteration, " + "it finds, for each word in the vector, its entry in the " + "container, using the find method" << endl; + cerr << "* Repeats the above test a number of times) " + << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_order_statistics_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_order_statistics_timing.cc new file mode 100644 index 000000000..95806685b --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_order_statistics_timing.cc @@ -0,0 +1,105 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_order_statistics_timing_test.cpp + * Contains test for order_statisticsing trees. + */ + +#include <iostream> +#include <vector> +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/tree_order_statistics_test.hpp> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + { + typedef tree_order_statistics_test< true> test_t; + test_t tst(vn, vs, vm); + typedef tree_common_types<int, __gnu_pbds::null_mapped_type, std::less<int>, __gnu_pbds::tree_order_statistics_node_update>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef tree_order_statistics_test<false> test_t; + test_t tst(vn, vs, vm); + typedef native_set<int> native_set_t; + tst(native_set_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: tree_order_statistics_timing_test.out <vn> <vs> <vm>" << + endl << endl; + + cerr << "This test checks the performance of order statistics" + " in tree based containers. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a tree" << endl; + cerr << "* Inserts integers into the tree" << endl; + cerr << "* Checks the order-statistics of each entry in the tree" << endl; + cerr << "* Repeats the above test some times" + << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the tree" << endl; + cerr << "vs = step size of the tree" << endl; + cerr << "vm = maximum size of the tree" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_split_join_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_split_join_timing.cc new file mode 100644 index 000000000..c10fe01cd --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_split_join_timing.cc @@ -0,0 +1,107 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_split_join_timing_test.cpp + * Contains test for joining trees. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <testsuite_rng.h> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/tree_split_join_test.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + { + typedef tree_split_join_test<true> test_t; + test_t tst(vn, vs, vm); + + typedef tree_common_types<int, __gnu_pbds::null_mapped_type>::performance_tl tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef tree_split_join_test<false> test_t; + test_t tst(vn, vs, vm); + typedef native_set<int> native_set_t; + tst(native_set_t()); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: tree_split_join_test.cpp <vn> <vs> <vm>" << + endl << endl; + + cerr << "This test checks the performance of splitting joining" + "tree based containers. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a tree " << endl; + cerr << "* Inserts integers into the tree" << endl; + cerr << "* Splits half the tree into a different tree" << endl; + cerr << "* Joins the trees" << endl; + cerr << "* Repeats the above test a given number of times) " + << endl; + + cerr << endl << endl; + + cerr << "vn = minimum size of the tree" << endl; + cerr << "vs = step size of the tree" << endl; + cerr << "vm = maximum size of the tree" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_insert_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_insert_timing.cc new file mode 100644 index 000000000..43466a2bf --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_insert_timing.cc @@ -0,0 +1,116 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_text_insert_timing_test.cpp + * Contains test for finding text. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/insert_test.hpp> +#include <io/text_populate.hpp> +#include <hash_fn/string_hash_fn.hpp> +#include <native_type/native_hash_map.hpp> +#include <native_type/native_map.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef insert_test< vec_t::const_iterator> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, vn, vs, vm); + { + typedef trie_common_types<std::string, char>::performance_tl pat_trie_tl_t; + typedef tree_common_types<std::string, char>::performance_tl tree_tl_t; + typedef __gnu_cxx::typelist::append<pat_trie_tl_t, tree_tl_t>::type tl_t; + tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + + { + typedef native_map<std::string, char> native_map_t; + tst(native_map_t()); + } + } + catch (...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: tree_text_insert_timing_test <f_name> <vn> <vs> <vm>" << + endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their insert method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Repeats the above test a number of times) " + << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} diff --git a/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_lor_find_timing.cc b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_lor_find_timing.cc new file mode 100644 index 000000000..dc205547d --- /dev/null +++ b/libstdc++-v3/testsuite/performance/ext/pb_ds/tree_text_lor_find_timing.cc @@ -0,0 +1,115 @@ +// -*- C++ -*- + +// Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software +// Foundation; either version 3, or (at your option) any later +// version. + +// This library is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this library; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + + +// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. + +// Permission to use, copy, modify, sell, and distribute this software +// is hereby granted without fee, provided that the above copyright +// notice appears in all copies, and that both that copyright notice +// and this permission notice appear in supporting documentation. None +// of the above authors, nor IBM Haifa Research Laboratories, make any +// representation about the suitability of this software for any +// purpose. It is provided "as is" without express or implied +// warranty. + +/** + * @file tree_text_lor_find_timing_test.cpp + * Contains test for finding text with locality of reference. + */ + +#include <ext/typelist.h> +#include <performance/io/xml_formatter.hpp> +#include <io/verified_cmd_line_input.hpp> +#include <common_type/assoc/common_type.hpp> +#include <performance/assoc/timing/find_test.hpp> +#include <io/text_populate.hpp> +#include <native_type/native_map.hpp> +#include <iostream> +#include <vector> + +void +usage(); + +int +main(int argc, char* a_p_argv[]) +{ + using namespace __gnu_pbds::test; + + std::string f_name = "thirty_years_among_the_dead_preproc.txt"; + size_t vn = 200; + size_t vs = 200; + size_t vm = 2100; + + try + { + xml_test_performance_formatter fmt("Size", "Average time (sec.)"); + + typedef std::vector<std::pair<std::string, char> > vec_t; + vec_t a_v(vm); + text_populate(f_name, a_v); + + typedef find_test<vec_t::const_iterator, true> test_t; + vec_t::const_iterator b = a_v.begin(); + test_t tst(b, b, vn, vs, vm, vn, vs, vm); + { + typedef native_map<std::string, char> native_set_t; + tst(native_set_t()); + } + + { + typedef tree_common_types<std::string, char>::performance_tl tree_tl_t; + tree_tl_t tl; + __gnu_cxx::typelist::apply(tst, tl); + } + } + catch(...) + { + std::cerr << "Test failed" << std::endl; + return -1; + } + return 0; +} + +void +usage() +{ + using namespace std; + cerr << "usage: tree_text_lor_find_performance_test <f_name> <vn> <vs> <vm>" + << endl << endl; + + cerr << + "This test checks the performance of various associative containers " + "using their find method. " << endl; + cerr << "Specifically, it does the following:" << endl; + cerr << "* Creates a vector of text words " << endl; + cerr << "* Inserts the elements into the container" << endl; + cerr << "* Performs a sequence of find operations. At each iteration, " + "it finds, for each word in the vector, its entry in the " + "container, using the find method" << endl; + cerr << "* Repeats the above test a number of times" << endl; + + cerr << endl << endl; + + cerr << "f_name = file name containing the text words. " + "Each line should contain one word." << endl; + cerr << "vn = minimum size of the vector" << endl; + cerr << "vs = step size of the vector" << endl; + cerr << "vm = maximum size of the vector" << endl; +} |