1 | // |
---|
2 | // Copyright (c) 2000-2002 |
---|
3 | // Joerg Walter, Mathias Koch |
---|
4 | // |
---|
5 | // Permission to use, copy, modify, distribute and sell this software |
---|
6 | // and its documentation for any purpose is hereby granted without fee, |
---|
7 | // provided that the above copyright notice appear in all copies and |
---|
8 | // that both that copyright notice and this permission notice appear |
---|
9 | // in supporting documentation. The authors make no representations |
---|
10 | // about the suitability of this software for any purpose. |
---|
11 | // It is provided "as is" without express or implied warranty. |
---|
12 | // |
---|
13 | // The authors gratefully acknowledge the support of |
---|
14 | // GeNeSys mbH & Co. KG in producing this work. |
---|
15 | // |
---|
16 | |
---|
17 | #include "bench3.hpp" |
---|
18 | |
---|
19 | void header (std::string text) { |
---|
20 | std::cout << text << std::endl; |
---|
21 | } |
---|
22 | |
---|
23 | template<class T> |
---|
24 | struct peak_c_plus { |
---|
25 | typedef T value_type; |
---|
26 | |
---|
27 | void operator () (int runs) const { |
---|
28 | try { |
---|
29 | static T s (0); |
---|
30 | boost::timer t; |
---|
31 | for (int i = 0; i < runs; ++ i) { |
---|
32 | s += T (0); |
---|
33 | // sink_scalar (s); |
---|
34 | } |
---|
35 | footer<value_type> () (0, 1, runs, t.elapsed ()); |
---|
36 | } |
---|
37 | catch (std::exception &e) { |
---|
38 | std::cout << e.what () << std::endl; |
---|
39 | } |
---|
40 | } |
---|
41 | }; |
---|
42 | template<class T> |
---|
43 | struct peak_c_multiplies { |
---|
44 | typedef T value_type; |
---|
45 | |
---|
46 | void operator () (int runs) const { |
---|
47 | try { |
---|
48 | static T s (1); |
---|
49 | boost::timer t; |
---|
50 | for (int i = 0; i < runs; ++ i) { |
---|
51 | s *= T (1); |
---|
52 | // sink_scalar (s); |
---|
53 | } |
---|
54 | footer<value_type> () (0, 1, runs, t.elapsed ()); |
---|
55 | } |
---|
56 | catch (std::exception &e) { |
---|
57 | std::cout << e.what () << std::endl; |
---|
58 | } |
---|
59 | } |
---|
60 | }; |
---|
61 | |
---|
62 | template<class T> |
---|
63 | void peak<T>::operator () (int runs) { |
---|
64 | header ("peak"); |
---|
65 | |
---|
66 | header ("plus"); |
---|
67 | peak_c_plus<T> () (runs); |
---|
68 | |
---|
69 | header ("multiplies"); |
---|
70 | peak_c_multiplies<T> () (runs); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | template <typename scalar> |
---|
75 | void do_bench (std::string type_string, int scale) |
---|
76 | { |
---|
77 | header (type_string); |
---|
78 | peak<scalar> () (1000000 * scale); |
---|
79 | |
---|
80 | header (type_string + ", 3"); |
---|
81 | bench_1<scalar, 3> () (1000000 * scale); |
---|
82 | bench_2<scalar, 3> () (300000 * scale); |
---|
83 | bench_3<scalar, 3> () (100000 * scale); |
---|
84 | |
---|
85 | header (type_string + ", 10"); |
---|
86 | bench_1<scalar, 10> () (300000 * scale); |
---|
87 | bench_2<scalar, 10> () (30000 * scale); |
---|
88 | bench_3<scalar, 10> () (3000 * scale); |
---|
89 | |
---|
90 | header (type_string + ", 30"); |
---|
91 | bench_1<scalar, 30> () (100000 * scale); |
---|
92 | bench_2<scalar, 30> () (3000 * scale); |
---|
93 | bench_3<scalar, 30> () (100 * scale); |
---|
94 | |
---|
95 | header (type_string + ", 100"); |
---|
96 | bench_1<scalar, 100> () (30000 * scale); |
---|
97 | bench_2<scalar, 100> () (300 * scale); |
---|
98 | bench_3<scalar, 100> () (3 * scale); |
---|
99 | } |
---|
100 | |
---|
101 | int main (int argc, char *argv []) { |
---|
102 | |
---|
103 | int scale = 1; |
---|
104 | if (argc > 1) |
---|
105 | scale = std::atoi (argv [1]); |
---|
106 | |
---|
107 | #ifdef USE_FLOAT |
---|
108 | do_bench<float> ("FLOAT", scale); |
---|
109 | #endif |
---|
110 | |
---|
111 | #ifdef USE_DOUBLE |
---|
112 | do_bench<double> ("DOUBLE", scale); |
---|
113 | #endif |
---|
114 | |
---|
115 | #ifdef USE_STD_COMPLEX |
---|
116 | #ifdef USE_FLOAT |
---|
117 | do_bench<std::complex<float> > ("COMPLEX<FLOAT>", scale); |
---|
118 | #endif |
---|
119 | |
---|
120 | #ifdef USE_DOUBLE |
---|
121 | do_bench<std::complex<double> > ("COMPLEX<DOUBLE>", scale); |
---|
122 | #endif |
---|
123 | #endif |
---|
124 | |
---|
125 | return 0; |
---|
126 | } |
---|