]>
Commit | Line | Data |
---|---|---|
fbd26352 | 1 | // Copyright (C) 2003-2019 Free Software Foundation, Inc. |
e6fb1577 | 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 | |
6bc9506f | 6 | // Free Software Foundation; either version 3, or (at your option) |
e6fb1577 | 7 | // any later version. |
8 | ||
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. | |
13 | ||
14 | // You should have received a copy of the GNU General Public License along | |
6bc9506f | 15 | // with this library; see the file COPYING3. If not see |
16 | // <http://www.gnu.org/licenses/>. | |
e6fb1577 | 17 | |
e6fb1577 | 18 | |
19 | #include <ctime> | |
20 | #include <iostream> | |
21 | #include <string> | |
ef8b25b2 | 22 | #include <testsuite_performance.h> |
e6fb1577 | 23 | |
24 | using namespace std; | |
25 | ||
26 | void | |
27 | test_append_char(int how_much) | |
28 | { | |
29 | string buf; // no preallocation | |
30 | for (int i = 0; i < how_much; ++i) | |
ef8b25b2 | 31 | buf.append(static_cast<string::size_type>(1) , 'x'); |
e6fb1577 | 32 | } |
33 | ||
34 | void | |
35 | test_append_string(int how_much) | |
36 | { | |
37 | string s(static_cast<string::size_type>(1) , 'x'); | |
38 | string buf; // no preallocation | |
39 | for (int i = 0; i < how_much; ++i) | |
ef8b25b2 | 40 | buf.append(s); |
e6fb1577 | 41 | } |
42 | ||
43 | void | |
44 | run_benchmark1(int how_much) | |
45 | { | |
56dcf3cc | 46 | using namespace __gnu_test; |
ef8b25b2 | 47 | time_counter time; |
48 | resource_counter resource; | |
49 | start_counters(time, resource); | |
e6fb1577 | 50 | test_append_char(how_much); |
ef8b25b2 | 51 | stop_counters(time, resource); |
52 | report_performance(__FILE__, "char", time, resource); | |
e6fb1577 | 53 | } |
54 | ||
55 | void | |
56 | run_benchmark2(int how_much) | |
57 | { | |
56dcf3cc | 58 | using namespace __gnu_test; |
ef8b25b2 | 59 | time_counter time; |
60 | resource_counter resource; | |
61 | start_counters(time, resource); | |
e6fb1577 | 62 | test_append_string(how_much); |
ef8b25b2 | 63 | stop_counters(time, resource); |
64 | report_performance(__FILE__, "string", time, resource); | |
e6fb1577 | 65 | } |
66 | ||
67 | // libstdc++/5380 | |
68 | // libstdc++/4960 | |
69 | int main() | |
70 | { | |
e6fb1577 | 71 | run_benchmark1(100000); |
72 | run_benchmark2(100000); | |
73 | run_benchmark1(1000000); | |
74 | run_benchmark2(1000000); | |
e0d46937 | 75 | run_benchmark1(10000000); |
76 | run_benchmark2(10000000); | |
e6fb1577 | 77 | } |