]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/performance/21_strings/string_append.cc
Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / performance / 21_strings / string_append.cc
CommitLineData
748086b7 1 // Copyright (C) 2003, 2009 Free Software Foundation, Inc.
ca5e1be8
BK
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
748086b7 6// Free Software Foundation; either version 3, or (at your option)
ca5e1be8
BK
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
748086b7
JJ
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
ca5e1be8 17
ca5e1be8
BK
18
19#include <ctime>
20#include <iostream>
21#include <string>
ce4f8c6b 22#include <testsuite_performance.h>
ca5e1be8
BK
23
24using namespace std;
25
26void
27test_append_char(int how_much)
28{
29 string buf; // no preallocation
30 for (int i = 0; i < how_much; ++i)
ce4f8c6b 31 buf.append(static_cast<string::size_type>(1) , 'x');
ca5e1be8
BK
32}
33
34void
35test_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)
ce4f8c6b 40 buf.append(s);
ca5e1be8
BK
41}
42
43void
44run_benchmark1(int how_much)
45{
aecf642c 46 using namespace __gnu_test;
ce4f8c6b
BK
47 time_counter time;
48 resource_counter resource;
49 start_counters(time, resource);
ca5e1be8 50 test_append_char(how_much);
ce4f8c6b
BK
51 stop_counters(time, resource);
52 report_performance(__FILE__, "char", time, resource);
ca5e1be8
BK
53}
54
55void
56run_benchmark2(int how_much)
57{
aecf642c 58 using namespace __gnu_test;
ce4f8c6b
BK
59 time_counter time;
60 resource_counter resource;
61 start_counters(time, resource);
ca5e1be8 62 test_append_string(how_much);
ce4f8c6b
BK
63 stop_counters(time, resource);
64 report_performance(__FILE__, "string", time, resource);
ca5e1be8
BK
65}
66
67// libstdc++/5380
68// libstdc++/4960
69int main()
70{
ca5e1be8
BK
71 run_benchmark1(100000);
72 run_benchmark2(100000);
73 run_benchmark1(1000000);
74 run_benchmark2(1000000);
9c519c93
PC
75 run_benchmark1(10000000);
76 run_benchmark2(10000000);
ca5e1be8 77}