* config/rs6000/40x.md (ppc403-compare): Remove "compare".
[official-gcc.git] / libstdc++-v3 / testsuite / performance / 21_strings / append-1.cc
blob5e4b913904b236e117d1ad6726f02651b91f7e2a
1 // Copyright (C) 2003-2014 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 #include <ctime>
20 #include <iostream>
21 #include <string>
22 #include <testsuite_performance.h>
24 using namespace std;
26 void
27 test_append_char(int how_much)
29 string buf; // no preallocation
30 for (int i = 0; i < how_much; ++i)
31 buf.append(static_cast<string::size_type>(1) , 'x');
34 void
35 test_append_string(int how_much)
37 string s(static_cast<string::size_type>(1) , 'x');
38 string buf; // no preallocation
39 for (int i = 0; i < how_much; ++i)
40 buf.append(s);
43 void
44 run_benchmark1(int how_much)
46 using namespace __gnu_test;
47 time_counter time;
48 resource_counter resource;
49 start_counters(time, resource);
50 test_append_char(how_much);
51 stop_counters(time, resource);
52 report_performance(__FILE__, "char", time, resource);
55 void
56 run_benchmark2(int how_much)
58 using namespace __gnu_test;
59 time_counter time;
60 resource_counter resource;
61 start_counters(time, resource);
62 test_append_string(how_much);
63 stop_counters(time, resource);
64 report_performance(__FILE__, "string", time, resource);
67 // libstdc++/5380
68 // libstdc++/4960
69 int main()
71 run_benchmark1(100000);
72 run_benchmark2(100000);
73 run_benchmark1(1000000);
74 run_benchmark2(1000000);
75 run_benchmark1(10000000);
76 run_benchmark2(10000000);