]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/benchmarks/bench1/bench11.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
), v2 (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
), v2 (N
), v3 (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
), v2 (N
), v3 (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
);
180 bench_my_inner_prod
<ublas::c_vector
<T
, N
>, N
> () (runs
);
183 #ifdef USE_BOUNDED_ARRAY
184 header ("vector<bounded_array>");
185 bench_my_inner_prod
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
);
188 #ifdef USE_UNBOUNDED_ARRAY
189 header ("vector<unbounded_array>");
190 bench_my_inner_prod
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
);
193 #ifdef USE_STD_VALARRAY
194 header ("vector<std::valarray>");
195 bench_my_inner_prod
<ublas::vector
<T
, std::valarray
<T
> >, N
> () ();
198 #ifdef USE_STD_VECTOR
199 header ("vector<std::vector>");
200 bench_my_inner_prod
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
);
203 #ifdef USE_STD_VALARRAY
204 header ("std::valarray");
205 bench_cpp_inner_prod
<std::valarray
<T
>, N
> () (runs
);
208 header ("vector + vector");
211 bench_c_vector_add
<T
, N
> () (runs
);
214 header ("c_vector safe");
215 bench_my_vector_add
<ublas::c_vector
<T
, N
>, N
> () (runs
, safe_tag ());
217 header ("c_vector fast");
218 bench_my_vector_add
<ublas::c_vector
<T
, N
>, N
> () (runs
, fast_tag ());
221 #ifdef USE_BOUNDED_ARRAY
222 header ("vector<bounded_array> safe");
223 bench_my_vector_add
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
, safe_tag ());
225 header ("vector<bounded_array> fast");
226 bench_my_vector_add
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
, fast_tag ());
229 #ifdef USE_UNBOUNDED_ARRAY
230 header ("vector<unbounded_array> safe");
231 bench_my_vector_add
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
, safe_tag ());
233 header ("vector<unbounded_array> fast");
234 bench_my_vector_add
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
, fast_tag ());
237 #ifdef USE_STD_VALARRAY
238 header ("vector<std::valarray> safe");
239 bench_my_vector_add
<ublas::vector
<T
, std::valarray
<T
> >, N
> () (runs
, safe_tag ());
241 header ("vector<std::valarray> fast");
242 bench_my_vector_add
<ublas::vector
<T
, std::valarray
<T
> >, N
> () (runs
, fast_tag ());
245 #ifdef USE_STD_VECTOR
246 header ("vector<std::vector> safe");
247 bench_my_vector_add
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
, safe_tag ());
249 header ("vector<std::vector> fast");
250 bench_my_vector_add
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
, fast_tag ());
253 #ifdef USE_STD_VALARRAY
254 header ("std::valarray");
255 bench_cpp_vector_add
<std::valarray
<T
>, N
> () (runs
);
260 template struct bench_1
<float, 3>;
261 template struct bench_1
<float, 10>;
262 template struct bench_1
<float, 30>;
263 template struct bench_1
<float, 100>;
267 template struct bench_1
<double, 3>;
268 template struct bench_1
<double, 10>;
269 template struct bench_1
<double, 30>;
270 template struct bench_1
<double, 100>;
273 #ifdef USE_STD_COMPLEX
275 template struct bench_1
<std::complex<float>, 3>;
276 template struct bench_1
<std::complex<float>, 10>;
277 template struct bench_1
<std::complex<float>, 30>;
278 template struct bench_1
<std::complex<float>, 100>;
282 template struct bench_1
<std::complex<double>, 3>;
283 template struct bench_1
<std::complex<double>, 10>;
284 template struct bench_1
<std::complex<double>, 30>;
285 template struct bench_1
<std::complex<double>, 100>;