]>
Commit | Line | Data |
---|---|---|
fbd26352 | 1 | // Copyright (C) 2012-2019 Free Software Foundation, Inc. |
00ba3421 | 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 | // { dg-do run { target c++11 } } | |
19 | ||
20 | #include <random> | |
21 | #include <vector> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_performance.h> | |
24 | ||
25 | int main() | |
26 | { | |
27 | using namespace __gnu_test; | |
28 | ||
29 | std::default_random_engine eng; | |
30 | std::uniform_int_distribution<unsigned> r(0, 127); | |
31 | ||
32 | time_counter time; | |
33 | resource_counter resource; | |
34 | ||
35 | std::vector<std::vector<char>> vecs(10000); | |
36 | for (auto& v : vecs) | |
37 | { | |
38 | v.resize(1000); | |
39 | for (auto& c : v) | |
40 | c = r(eng); | |
41 | } | |
42 | ||
43 | start_counters(time, resource); | |
44 | std::vector<char> res; | |
45 | for (auto& v : vecs) | |
46 | res.insert(res.begin(), v.begin(), v.end()); | |
47 | stop_counters(time, resource); | |
48 | report_performance(__FILE__, "insert pointers", time, resource); | |
49 | ||
50 | struct input_iterator : std::vector<char>::iterator | |
51 | { | |
52 | using iterator_category = std::input_iterator_tag; | |
53 | using base = std::vector<char>::iterator; | |
54 | ||
55 | input_iterator(base it) : base(it) { } | |
56 | }; | |
57 | ||
58 | start_counters(time, resource); | |
59 | std::vector<char> res2; | |
60 | for (auto& v : vecs) | |
61 | { | |
62 | auto begin = input_iterator(v.begin()); | |
63 | auto end = input_iterator(v.end()); | |
64 | res2.insert(res2.begin(), begin, end); | |
65 | } | |
66 | stop_counters(time, resource); | |
67 | report_performance(__FILE__, "insert input iterators", time, resource); | |
68 | ||
69 | start_counters(time, resource); | |
70 | std::vector<char> res3; | |
71 | for (auto rev = vecs.rbegin(); rev != vecs.rend(); ++rev) | |
72 | res3.insert(res3.end(), rev->begin(), rev->end()); | |
73 | stop_counters(time, resource); | |
74 | report_performance(__FILE__, "insert pointers end", time, resource); | |
75 | ||
76 | start_counters(time, resource); | |
77 | std::vector<char> res4; | |
78 | for (auto rev = vecs.rbegin(); rev != vecs.rend(); ++rev) | |
79 | res4.insert(res4.end(), rev->begin(), rev->end()); | |
80 | stop_counters(time, resource); | |
81 | report_performance(__FILE__, "insert input iterators end", time, resource); | |
82 | ||
83 | VERIFY(res2 == res); | |
84 | VERIFY(res3 == res); | |
85 | VERIFY(res4 == res); | |
86 | } |