]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/benchmarks/bench2/bench21.cpp
2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // The authors gratefully acknowledge the support of
10 // GeNeSys mbH & Co. KG in producing this work.
15 template<class T
, int N
>
16 struct bench_c_inner_prod
{
19 void operator () (int runs
) const {
21 static typename c_vector_traits
<T
, N
>::type v1
, v2
;
22 initialize_c_vector
<T
, N
> () (v1
);
23 initialize_c_vector
<T
, N
> () (v2
);
25 for (int i
= 0; i
< runs
; ++ i
) {
26 static value_type
s (0);
27 for (int j
= 0; j
< N
; ++ j
) {
32 footer
<value_type
> () (N
, N
- 1, runs
, t
.elapsed ());
34 catch (std::exception
&e
) {
35 std::cout
<< e
.what () << std::endl
;
39 template<class V
, int N
>
40 struct bench_my_inner_prod
{
41 typedef typename
V::value_type value_type
;
43 void operator () (int runs
) const {
45 static V
v1 (N
, N
), v2 (N
, N
);
46 initialize_vector (v1
);
47 initialize_vector (v2
);
49 for (int i
= 0; i
< runs
; ++ i
) {
50 static value_type
s (0);
51 s
= ublas::inner_prod (v1
, v2
);
53 BOOST_UBLAS_NOT_USED(s
);
55 footer
<value_type
> () (N
, N
- 1, runs
, t
.elapsed ());
57 catch (std::exception
&e
) {
58 std::cout
<< e
.what () << std::endl
;
62 template<class V
, int N
>
63 struct bench_cpp_inner_prod
{
64 typedef typename
V::value_type value_type
;
66 void operator () (int runs
) const {
68 static V
v1 (N
), v2 (N
);
69 initialize_vector (v1
);
70 initialize_vector (v2
);
72 for (int i
= 0; i
< runs
; ++ i
) {
73 static value_type
s (0);
77 footer
<value_type
> () (N
, N
- 1, runs
, t
.elapsed ());
79 catch (std::exception
&e
) {
80 std::cout
<< e
.what () << std::endl
;
85 template<class T
, int N
>
86 struct bench_c_vector_add
{
89 void operator () (int runs
) const {
91 static typename c_vector_traits
<T
, N
>::type v1
, v2
, v3
;
92 initialize_c_vector
<T
, N
> () (v1
);
93 initialize_c_vector
<T
, N
> () (v2
);
95 for (int i
= 0; i
< runs
; ++ i
) {
96 for (int j
= 0; j
< N
; ++ j
) {
97 v3
[j
] = - (v1
[j
] + v2
[j
]);
99 // sink_c_vector<T, N> () (v3);
100 BOOST_UBLAS_NOT_USED(v3
);
102 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
104 catch (std::exception
&e
) {
105 std::cout
<< e
.what () << std::endl
;
109 template<class V
, int N
>
110 struct bench_my_vector_add
{
111 typedef typename
V::value_type value_type
;
113 void operator () (int runs
, safe_tag
) const {
115 static V
v1 (N
, N
), v2 (N
, N
), v3 (N
, N
);
116 initialize_vector (v1
);
117 initialize_vector (v2
);
119 for (int i
= 0; i
< runs
; ++ i
) {
123 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
125 catch (std::exception
&e
) {
126 std::cout
<< e
.what () << std::endl
;
129 void operator () (int runs
, fast_tag
) const {
131 static V
v1 (N
, N
), v2 (N
, N
), v3 (N
, N
);
132 initialize_vector (v1
);
133 initialize_vector (v2
);
135 for (int i
= 0; i
< runs
; ++ i
) {
136 v3
.assign (- (v1
+ v2
));
139 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
141 catch (std::exception
&e
) {
142 std::cout
<< e
.what () << std::endl
;
146 template<class V
, int N
>
147 struct bench_cpp_vector_add
{
148 typedef typename
V::value_type value_type
;
150 void operator () (int runs
) const {
152 static V
v1 (N
), v2 (N
), v3 (N
);
153 initialize_vector (v1
);
154 initialize_vector (v2
);
156 for (int i
= 0; i
< runs
; ++ i
) {
160 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
162 catch (std::exception
&e
) {
163 std::cout
<< e
.what () << std::endl
;
169 template<class T
, int N
>
170 void bench_1
<T
, N
>::operator () (int runs
) {
173 header ("inner_prod");
176 bench_c_inner_prod
<T
, N
> () (runs
);
178 #ifdef USE_MAPPED_VECTOR
180 header ("mapped_vector<map_array>");
181 bench_my_inner_prod
<ublas::mapped_vector
<T
, ublas::map_array
<std::size_t, T
> >, N
> () (runs
);
185 header ("mapped_vector<std::map>");
186 bench_my_inner_prod
<ublas::mapped_vector
<T
, std::map
<std::size_t, T
> >, N
> () (runs
);
190 #ifdef USE_COMPRESSED_VECTOR
191 header ("compressed_vector");
192 bench_my_inner_prod
<ublas::compressed_vector
<T
>, N
> () (runs
);
195 #ifdef USE_COORDINATE_VECTOR
196 header ("coordinate_vector");
197 bench_my_inner_prod
<ublas::coordinate_vector
<T
>, N
> () (runs
);
200 #ifdef USE_STD_VALARRAY
201 header ("std::valarray");
202 bench_cpp_inner_prod
<std::valarray
<T
>, N
> () (runs
);
205 header ("vector + vector");
208 bench_c_vector_add
<T
, N
> () (runs
);
210 #ifdef USE_MAPPED_VECTOR
212 header ("mapped_vector<map_array> safe");
213 bench_my_vector_add
<ublas::mapped_vector
<T
, ublas::map_array
<std::size_t, T
> >, N
> () (runs
, safe_tag ());
215 header ("maped_vector<map_array> fast");
216 bench_my_vector_add
<ublas::mapped_vector
<T
, ublas::map_array
<std::size_t, T
> >, N
> () (runs
, fast_tag ());
220 header ("mapped_vector<std::map> safe");
221 bench_my_vector_add
<ublas::mapped_vector
<T
, std::map
<std::size_t, T
> >, N
> () (runs
, safe_tag ());
223 header ("mapped_vector<std::map> fast");
224 bench_my_vector_add
<ublas::mapped_vector
<T
, std::map
<std::size_t, T
> >, N
> () (runs
, fast_tag ());
228 #ifdef USE_COMPRESSED_VECTOR
230 header ("compressed_vector safe");
231 bench_my_vector_add
<ublas::compressed_vector
<T
>, N
> () (runs
, safe_tag ());
233 header ("compressed_vector fast");
234 bench_my_vector_add
<ublas::compressed_vector
<T
>, N
> () (runs
, fast_tag ());
238 #ifdef USE_COORDINATE_VECTOR
240 header ("coordinate_vector safe");
241 bench_my_vector_add
<ublas::coordinate_vector
<T
>, N
> () (runs
, safe_tag ());
243 header ("coordinate_vector fast");
244 bench_my_vector_add
<ublas::coordinate_vector
<T
>, N
> () (runs
, fast_tag ());
248 #ifdef USE_STD_VALARRAY
249 header ("std::valarray");
250 bench_cpp_vector_add
<std::valarray
<T
>, N
> () (runs
);
255 template struct bench_1
<float, 3>;
256 template struct bench_1
<float, 10>;
257 template struct bench_1
<float, 30>;
258 template struct bench_1
<float, 100>;
262 template struct bench_1
<double, 3>;
263 template struct bench_1
<double, 10>;
264 template struct bench_1
<double, 30>;
265 template struct bench_1
<double, 100>;
268 #ifdef USE_STD_COMPLEX
270 template struct bench_1
<std::complex<float>, 3>;
271 template struct bench_1
<std::complex<float>, 10>;
272 template struct bench_1
<std::complex<float>, 30>;
273 template struct bench_1
<std::complex<float>, 100>;
277 template struct bench_1
<std::complex<double>, 3>;
278 template struct bench_1
<std::complex<double>, 10>;
279 template struct bench_1
<std::complex<double>, 30>;
280 template struct bench_1
<std::complex<double>, 100>;