]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/ublas/benchmarks/bench3/bench31.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 ublas::vector_range
<V
> vr1 (v1
, ublas::range (0, N
)),
47 vr2 (v2
, ublas::range (0, N
));
48 initialize_vector (vr1
);
49 initialize_vector (vr2
);
51 for (int i
= 0; i
< runs
; ++ i
) {
52 static value_type
s (0);
53 s
= ublas::inner_prod (vr1
, vr2
);
55 BOOST_UBLAS_NOT_USED(s
);
57 footer
<value_type
> () (N
, N
- 1, runs
, t
.elapsed ());
59 catch (std::exception
&e
) {
60 std::cout
<< e
.what () << std::endl
;
64 template<class V
, int N
>
65 struct bench_cpp_inner_prod
{
66 typedef typename
V::value_type value_type
;
68 void operator () (int runs
) const {
70 static V
v1 (N
), v2 (N
);
71 initialize_vector (v1
);
72 initialize_vector (v2
);
74 for (int i
= 0; i
< runs
; ++ i
) {
75 static value_type
s (0);
79 footer
<value_type
> () (N
, N
- 1, runs
, t
.elapsed ());
81 catch (std::exception
&e
) {
82 std::cout
<< e
.what () << std::endl
;
87 template<class T
, int N
>
88 struct bench_c_vector_add
{
91 void operator () (int runs
) const {
93 static typename c_vector_traits
<T
, N
>::type v1
, v2
, v3
;
94 initialize_c_vector
<T
, N
> () (v1
);
95 initialize_c_vector
<T
, N
> () (v2
);
97 for (int i
= 0; i
< runs
; ++ i
) {
98 for (int j
= 0; j
< N
; ++ j
) {
99 v3
[j
] = - (v1
[j
] + v2
[j
]);
101 // sink_c_vector<T, N> () (v3);
102 BOOST_UBLAS_NOT_USED(v3
);
104 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
106 catch (std::exception
&e
) {
107 std::cout
<< e
.what () << std::endl
;
111 template<class V
, int N
>
112 struct bench_my_vector_add
{
113 typedef typename
V::value_type value_type
;
115 void operator () (int runs
, safe_tag
) const {
117 static V
v1 (N
), v2 (N
), v3 (N
);
118 ublas::vector_range
<V
> vr1 (v1
, ublas::range (0, N
)),
119 vr2 (v2
, ublas::range (0, N
)),
120 vr3 (v2
, ublas::range (0, N
));
121 initialize_vector (vr1
);
122 initialize_vector (vr2
);
123 initialize_vector (vr3
);
125 for (int i
= 0; i
< runs
; ++ i
) {
127 // sink_vector (vr3);
129 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
131 catch (std::exception
&e
) {
132 std::cout
<< e
.what () << std::endl
;
135 void operator () (int runs
, fast_tag
) const {
137 static V
v1 (N
), v2 (N
), v3 (N
);
138 ublas::vector_range
<V
> vr1 (v1
, ublas::range (0, N
)),
139 vr2 (v2
, ublas::range (0, N
)),
140 vr3 (v2
, ublas::range (0, N
));
141 initialize_vector (vr1
);
142 initialize_vector (vr2
);
144 for (int i
= 0; i
< runs
; ++ i
) {
145 vr3
.assign (- (vr1
+ vr2
));
146 // sink_vector (vr3);
148 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
150 catch (std::exception
&e
) {
151 std::cout
<< e
.what () << std::endl
;
155 template<class V
, int N
>
156 struct bench_cpp_vector_add
{
157 typedef typename
V::value_type value_type
;
159 void operator () (int runs
) const {
161 static V
v1 (N
), v2 (N
), v3 (N
);
162 initialize_vector (v1
);
163 initialize_vector (v2
);
165 for (int i
= 0; i
< runs
; ++ i
) {
169 footer
<value_type
> () (0, 2 * N
, runs
, t
.elapsed ());
171 catch (std::exception
&e
) {
172 std::cout
<< e
.what () << std::endl
;
178 template<class T
, int N
>
179 void bench_1
<T
, N
>::operator () (int runs
) {
182 header ("inner_prod");
185 bench_c_inner_prod
<T
, N
> () (runs
);
189 bench_my_inner_prod
<ublas::c_vector
<T
, N
>, N
> () (runs
);
192 #ifdef USE_BOUNDED_ARRAY
193 header ("vector<bounded_array>");
194 bench_my_inner_prod
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
);
197 #ifdef USE_UNBOUNDED_ARRAY
198 header ("vector<unbounded_array>");
199 bench_my_inner_prod
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
);
202 #ifdef USE_STD_VALARRAY
203 header ("vector<std::valarray>");
204 bench_my_inner_prod
<ublas::vector
<T
, std::valarray
<T
> >, N
> () ();
207 #ifdef USE_STD_VECTOR
208 header ("vector<std::vector>");
209 bench_my_inner_prod
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
);
212 #ifdef USE_STD_VALARRAY
213 header ("std::valarray");
214 bench_cpp_inner_prod
<std::valarray
<T
>, N
> () (runs
);
217 header ("vector + vector");
220 bench_c_vector_add
<T
, N
> () (runs
);
223 header ("c_vector safe");
224 bench_my_vector_add
<ublas::c_vector
<T
, N
>, N
> () (runs
, safe_tag ());
226 header ("c_vector fast");
227 bench_my_vector_add
<ublas::c_vector
<T
, N
>, N
> () (runs
, fast_tag ());
230 #ifdef USE_BOUNDED_ARRAY
231 header ("vector<bounded_array> safe");
232 bench_my_vector_add
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
, safe_tag ());
234 header ("vector<bounded_array> fast");
235 bench_my_vector_add
<ublas::vector
<T
, ublas::bounded_array
<T
, N
> >, N
> () (runs
, fast_tag ());
238 #ifdef USE_UNBOUNDED_ARRAY
239 header ("vector<unbounded_array> safe");
240 bench_my_vector_add
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
, safe_tag ());
242 header ("vector<unbounded_array> fast");
243 bench_my_vector_add
<ublas::vector
<T
, ublas::unbounded_array
<T
> >, N
> () (runs
, fast_tag ());
246 #ifdef USE_STD_VALARRAY
247 header ("vector<std::valarray> safe");
248 bench_my_vector_add
<ublas::vector
<T
, std::valarray
<T
> >, N
> () (runs
, safe_tag ());
250 header ("vector<std::valarray> fast");
251 bench_my_vector_add
<ublas::vector
<T
, std::valarray
<T
> >, N
> () (runs
, fast_tag ());
254 #ifdef USE_STD_VECTOR
255 header ("vector<std::vector> safe");
256 bench_my_vector_add
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
, safe_tag ());
258 header ("vector<std::vector> fast");
259 bench_my_vector_add
<ublas::vector
<T
, std::vector
<T
> >, N
> () (runs
, fast_tag ());
262 #ifdef USE_STD_VALARRAY
263 header ("std::valarray");
264 bench_cpp_vector_add
<std::valarray
<T
>, N
> () (runs
);
269 template struct bench_1
<float, 3>;
270 template struct bench_1
<float, 10>;
271 template struct bench_1
<float, 30>;
272 template struct bench_1
<float, 100>;
276 template struct bench_1
<double, 3>;
277 template struct bench_1
<double, 10>;
278 template struct bench_1
<double, 30>;
279 template struct bench_1
<double, 100>;
282 #ifdef USE_STD_COMPLEX
284 template struct bench_1
<std::complex<float>, 3>;
285 template struct bench_1
<std::complex<float>, 10>;
286 template struct bench_1
<std::complex<float>, 30>;
287 template struct bench_1
<std::complex<float>, 100>;
291 template struct bench_1
<std::complex<double>, 3>;
292 template struct bench_1
<std::complex<double>, 10>;
293 template struct bench_1
<std::complex<double>, 30>;
294 template struct bench_1
<std::complex<double>, 100>;