]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/performance/23_containers/insert_from_sorted/set.cc
1 // Copyright (C) 2003-2023 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/>.
19 #include <testsuite_performance.h>
21 template<typename Container
, int Iter
>
25 // avoid excessive swap file use!
26 static const unsigned max_size
= 250000;
28 // make results less random while
29 static const unsigned iterations
= 10;
31 // keeping the total time reasonable
32 static const unsigned step
= 50000;
35 typedef int test_type
;
36 typedef Container container_type
;
37 typedef vector
<test_type
> vector_type
;
39 // Initialize sorted array.
40 vector_type
v(max_size
, 0);
41 for (unsigned int i
= 0; i
!= max_size
; ++i
)
44 for (unsigned int count
= step
; count
<= max_size
; count
+= step
)
46 for (unsigned i
= 0; i
!= iterations
; ++i
)
48 container_type test_set
;
49 typename
container_type::iterator iter
= test_set
.end();
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
]);
63 #define thread_type false
67 #define thread_type true
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());