]>
Commit | Line | Data |
---|---|---|
1 | // Copyright (C) 2006-2020 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. | |
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 | |
15 | // with this library; see the file COPYING3. If not see | |
16 | // <http://www.gnu.org/licenses/>. | |
17 | ||
18 | ||
19 | #include <iterator> | |
20 | #include <sstream> | |
21 | #include <algorithm> | |
22 | #include <testsuite_performance.h> | |
23 | ||
24 | // libstdc++/25482 | |
25 | int main() | |
26 | { | |
27 | using namespace std; | |
28 | using namespace __gnu_test; | |
29 | ||
30 | typedef istreambuf_iterator<char> in_iterator_type; | |
31 | typedef ostreambuf_iterator<char> out_iterator_type; | |
32 | ||
33 | time_counter time; | |
34 | resource_counter resource; | |
35 | ||
36 | const char data[] = "Contrappunto dialettico alla mente"; | |
37 | ||
38 | // istreambuf iterators -> ostreambuf iterator | |
39 | { | |
40 | istringstream iss(data); | |
41 | in_iterator_type beg(iss); | |
42 | in_iterator_type end; | |
43 | ||
44 | ostringstream oss; | |
45 | out_iterator_type out(oss); | |
46 | ||
47 | start_counters(time, resource); | |
48 | for (unsigned i = 0; i < 10000000; ++i) | |
49 | { | |
50 | copy(beg, end, out); | |
51 | iss.seekg(0); | |
52 | oss.seekp(0); | |
53 | } | |
54 | stop_counters(time, resource); | |
55 | report_performance(__FILE__, "isb iters -> osb iter", time, resource); | |
56 | clear_counters(time, resource); | |
57 | } | |
58 | ||
59 | // char array -> ostreambuf iterator | |
60 | { | |
61 | const char* beg = data; | |
62 | const char* end = data + sizeof(data) - 1; | |
63 | ||
64 | ostringstream oss; | |
65 | out_iterator_type out(oss); | |
66 | ||
67 | start_counters(time, resource); | |
68 | for (unsigned i = 0; i < 10000000; ++i) | |
69 | { | |
70 | copy(beg, end, out); | |
71 | oss.seekp(0); | |
72 | } | |
73 | stop_counters(time, resource); | |
74 | report_performance(__FILE__, "pointers -> osb iter", time, resource); | |
75 | clear_counters(time, resource); | |
76 | } | |
77 | ||
78 | // istreambuf iterators -> char array | |
79 | { | |
80 | istringstream iss(data); | |
81 | in_iterator_type beg(iss); | |
82 | in_iterator_type end; | |
83 | ||
84 | char out[sizeof(data)]; | |
85 | ||
86 | start_counters(time, resource); | |
87 | for (unsigned i = 0; i < 10000000; ++i) | |
88 | { | |
89 | copy(beg, end, out); | |
90 | iss.seekg(0); | |
91 | } | |
92 | stop_counters(time, resource); | |
93 | report_performance(__FILE__, "isb iters -> pointer", time, resource); | |
94 | clear_counters(time, resource); | |
95 | } | |
96 | ||
97 | return 0; | |
98 | } |