]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / performance / 23_containers / insert_from_sorted / set.cc
1 // Copyright (C) 2003-2022 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 <testsuite_performance.h>
20
21 template<typename Container, int Iter>
22 void
23 do_loop()
24 {
25 // avoid excessive swap file use!
26 static const unsigned max_size = 250000;
27
28 // make results less random while
29 static const unsigned iterations = 10;
30
31 // keeping the total time reasonable
32 static const unsigned step = 50000;
33
34 using namespace std;
35 typedef int test_type;
36 typedef Container container_type;
37 typedef vector<test_type> vector_type;
38
39 // Initialize sorted array.
40 vector_type v(max_size, 0);
41 for (unsigned int i = 0; i != max_size; ++i)
42 v[i] = i;
43
44 for (unsigned int count = step; count <= max_size; count += step)
45 {
46 for (unsigned i = 0; i != iterations; ++i)
47 {
48 container_type test_set;
49 typename container_type::iterator iter = test_set.end();
50
51 // Each insert in amortized constant time (Table 69)
52 for (unsigned j = 0; j != count; ++j)
53 iter = test_set.insert(iter, v[j]);
54 }
55 }
56
57 }
58
59 int
60 main()
61 {
62 #ifdef TEST_S1
63 #define thread_type false
64 #endif
65
66 #ifdef TEST_T1
67 #define thread_type true
68 #endif
69
70 typedef __gnu_test::sets<int, thread_type>::type container_types;
71 typedef test_sequence<thread_type> test_type;
72 test_type test("insert_from_sorted");
73 __gnu_cxx::typelist::apply(test, container_types());
74
75 return 0;
76 }
77