1 // Copyright (C) 2012-2024 Free Software Foundation, Inc.
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)
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/>.
18 // { dg-do run { target c++11 } }
22 #include <testsuite_hooks.h>
23 #include <testsuite_performance.h>
27 using namespace __gnu_test
;
29 std::default_random_engine eng
;
30 std::uniform_int_distribution
<unsigned> r(0, 127);
33 resource_counter resource
;
35 std::vector
<std::vector
<char>> vecs(10000);
43 start_counters(time
, resource
);
44 std::vector
<char> res
;
46 res
.insert(res
.begin(), v
.begin(), v
.end());
47 stop_counters(time
, resource
);
48 report_performance(__FILE__
, "insert pointers", time
, resource
);
50 struct input_iterator
: std::vector
<char>::iterator
52 using iterator_category
= std::input_iterator_tag
;
53 using base
= std::vector
<char>::iterator
;
55 input_iterator(base it
) : base(it
) { }
58 start_counters(time
, resource
);
59 std::vector
<char> res2
;
62 auto begin
= input_iterator(v
.begin());
63 auto end
= input_iterator(v
.end());
64 res2
.insert(res2
.begin(), begin
, end
);
66 stop_counters(time
, resource
);
67 report_performance(__FILE__
, "insert input iterators", time
, resource
);
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
);
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
);