1 // Copyright (C) 2004-2025 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/>.
20 * The goal with this application is to compare the performance
21 * between different std::allocator implementations. The results are
22 * influenced by the underlying allocator in the "C" library, malloc.
30 typedef int test_type
;
32 // This can take extremely long on simulators, timing out the test.
33 // { dg-options "-DITERATIONS=10" { target simulator } }
35 #define ITERATIONS 10000
38 // The number of iterations to be performed.
39 int iterations
= ITERATIONS
;
41 // The number of values to insert in the container, 32 will cause 5
42 // (re)allocations to be performed (sizes 4, 8, 16, 32 and 64)
43 // This means that all allocations are within _MAX_BYTES = 128 as
44 // defined in stl_alloc.h for __pool_alloc. Whether or not this
45 // value is relevant in "the real world" or not I don't know and
46 // should probably be investigated in more detail.
47 int insert_values
= 128;
49 template<typename TestType
>
50 struct value_type
: public pair
<TestType
, TestType
>
52 value_type() : pair
<TestType
, TestType
>(0, 0) { }
54 inline value_type
operator++() { return ++this->first
, *this; }
55 inline operator TestType() const { return this->first
; }
58 template<typename Container
>
63 int test_iterations
= 0;
64 value_type
<test_type
> test_value
;
65 while (test_iterations
< iterations
)
67 for (int j
= 0; j
< insert_values
; ++j
)
68 obj
.insert(obj
.end(), ++test_value
);
73 template<typename Container
>
75 test_container(Container
, bool run_threaded
= false)
78 std::ostringstream comment
;
80 comment
<< "4-way threaded iterations: " << iterations
*4 << '\t';
82 comment
<< "iterations: " << iterations
<< '\t';
85 // http://gcc.gnu.org/ml/libstdc++/2001-05/msg00105.html
86 // http://gcc.gnu.org/ml/libstdc++/2003-05/msg00231.html
89 typedef less
<test_type
> compare_type
;
90 test_container(set
<test_type
, compare_type
>());