]>
Commit | Line | Data |
---|---|---|
f474835b | 1 | // Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
402b0954 LR |
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 2, 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 COPYING. If not, write to the Free | |
16 | // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
17 | // USA. | |
18 | ||
19 | // As a special exception, you may use this file as part of a free software | |
20 | // library without restriction. Specifically, if other files instantiate | |
21 | // templates or use macros or inline functions from this file, or you compile | |
22 | // this file and link it with other files to produce an executable, this | |
23 | // file does not by itself cause the resulting executable to be covered by | |
24 | // the GNU General Public License. This exception does not however | |
25 | // invalidate any other reasons why the executable file might be covered by | |
26 | // the GNU General Public License. | |
27 | ||
28 | /* | |
29 | * The goal with this application is to compare the performance | |
30 | * between different std::allocator implementations. The results are | |
31 | * influenced by the underlying allocator in the "C" library, malloc. | |
32 | */ | |
33 | ||
34 | // libstdc++/13823 recast for this testing framework | |
35 | ||
36 | #include <map> | |
37 | #include <iostream> | |
38 | #include <typeinfo> | |
39 | #include <sstream> | |
402b0954 | 40 | #include <ext/mt_allocator.h> |
f64f4406 | 41 | #include <ext/new_allocator.h> |
402b0954 | 42 | #include <ext/malloc_allocator.h> |
009368db | 43 | #include <ext/bitmap_allocator.h> |
29d4adf4 | 44 | #include <ext/pool_allocator.h> |
f64f4406 | 45 | #include <cxxabi.h> |
402b0954 LR |
46 | #include <testsuite_performance.h> |
47 | ||
48 | using namespace std; | |
402b0954 | 49 | using __gnu_cxx::__mt_alloc; |
f64f4406 LR |
50 | using __gnu_cxx::new_allocator; |
51 | using __gnu_cxx::malloc_allocator; | |
009368db | 52 | using __gnu_cxx::bitmap_allocator; |
29d4adf4 | 53 | using __gnu_cxx::__pool_alloc; |
402b0954 LR |
54 | |
55 | // The number of iterations to be performed. | |
093b46f0 | 56 | int iterations = 10000; |
402b0954 LR |
57 | |
58 | template<typename Container> | |
59 | void* | |
60 | do_loop(void* p = NULL) | |
61 | { | |
62 | try | |
63 | { | |
64 | for (int c = 0; c < 10; c++) | |
65 | { | |
66 | Container m; | |
402b0954 LR |
67 | for (unsigned i = 0; i < iterations; ++i) |
68 | m[i] = i; | |
69 | } | |
70 | } | |
71 | catch(...) | |
72 | { | |
73 | // No point allocating all available memory, repeatedly. | |
74 | } | |
f474835b | 75 | return p; |
402b0954 LR |
76 | } |
77 | ||
402b0954 LR |
78 | template<typename Container> |
79 | void | |
80 | test_container(Container obj) | |
81 | { | |
82 | using namespace __gnu_test; | |
83 | int status; | |
84 | ||
85 | time_counter time; | |
86 | resource_counter resource; | |
87 | ||
402b0954 LR |
88 | start_counters(time, resource); |
89 | ||
90 | pthread_t t1, t2, t3, t4; | |
91 | pthread_create(&t1, NULL, &do_loop<Container>, NULL); | |
92 | pthread_create(&t2, NULL, &do_loop<Container>, NULL); | |
93 | pthread_create(&t3, NULL, &do_loop<Container>, NULL); | |
94 | pthread_create(&t4, NULL, &do_loop<Container>, NULL); | |
95 | ||
96 | pthread_join(t1, NULL); | |
97 | pthread_join(t2, NULL); | |
98 | pthread_join(t3, NULL); | |
99 | pthread_join(t4, NULL); | |
100 | ||
101 | stop_counters(time, resource); | |
102 | ||
103 | std::ostringstream comment; | |
104 | comment << "iterations: " << iterations << '\t'; | |
105 | comment << "type: " << abi::__cxa_demangle(typeid(obj).name(), | |
106 | 0, 0, &status); | |
107 | report_header(__FILE__, comment.str()); | |
108 | report_performance(__FILE__, string(), time, resource); | |
109 | } | |
110 | ||
111 | int main(void) | |
112 | { | |
1b90e7a3 PC |
113 | typedef pair<const int, int> pair_type; |
114 | ||
c8333c0f | 115 | #ifdef TEST_T0 |
402b0954 | 116 | test_container(map<int, int>()); |
f64f4406 | 117 | #endif |
c8333c0f | 118 | #ifdef TEST_T1 |
1b90e7a3 PC |
119 | test_container(map<int, int, less<const int>, |
120 | new_allocator<pair_type> >()); | |
f64f4406 | 121 | #endif |
c8333c0f | 122 | #ifdef TEST_T2 |
1b90e7a3 PC |
123 | test_container(map<int, int, less<const int>, |
124 | malloc_allocator<pair_type> >()); | |
f64f4406 | 125 | #endif |
c8333c0f | 126 | #ifdef TEST_T3 |
402b0954 | 127 | test_container(map<int, int, less<const int>, |
1b90e7a3 | 128 | __mt_alloc<pair_type> >()); |
f64f4406 | 129 | #endif |
c8333c0f | 130 | #ifdef TEST_T4 |
1b90e7a3 PC |
131 | test_container(map<int, int, less<const int>, |
132 | bitmap_allocator<pair_type> >()); | |
009368db | 133 | #endif |
c8333c0f | 134 | #ifdef TEST_T5 |
1b90e7a3 PC |
135 | test_container(map<int, int, less<const int>, |
136 | __pool_alloc<pair_type> >()); | |
29d4adf4 | 137 | #endif |
402b0954 LR |
138 | return 0; |
139 | } |