| 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 <boost/numeric/interval.hpp> |
|---|
| 18 | #include <boost/numeric/interval/io.hpp> |
|---|
| 19 | #include "../bench1/bench1.hpp" |
|---|
| 20 | |
|---|
| 21 | void header (std::string text) { |
|---|
| 22 | std::cout << text << std::endl; |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | template<class T> |
|---|
| 26 | struct peak_c_plus { |
|---|
| 27 | typedef T value_type; |
|---|
| 28 | |
|---|
| 29 | void operator () (int runs) const { |
|---|
| 30 | try { |
|---|
| 31 | static T s (0); |
|---|
| 32 | boost::timer t; |
|---|
| 33 | for (int i = 0; i < runs; ++ i) { |
|---|
| 34 | s += T (0); |
|---|
| 35 | // sink_scalar (s); |
|---|
| 36 | } |
|---|
| 37 | footer<value_type> () (0, 1, runs, t.elapsed ()); |
|---|
| 38 | } |
|---|
| 39 | catch (std::exception &e) { |
|---|
| 40 | std::cout << e.what () << std::endl; |
|---|
| 41 | } |
|---|
| 42 | } |
|---|
| 43 | }; |
|---|
| 44 | template<class T> |
|---|
| 45 | struct peak_c_multiplies { |
|---|
| 46 | typedef T value_type; |
|---|
| 47 | |
|---|
| 48 | void operator () (int runs) const { |
|---|
| 49 | try { |
|---|
| 50 | static T s (1); |
|---|
| 51 | boost::timer t; |
|---|
| 52 | for (int i = 0; i < runs; ++ i) { |
|---|
| 53 | s *= T (1); |
|---|
| 54 | // sink_scalar (s); |
|---|
| 55 | } |
|---|
| 56 | footer<value_type> () (0, 1, runs, t.elapsed ()); |
|---|
| 57 | } |
|---|
| 58 | catch (std::exception &e) { |
|---|
| 59 | std::cout << e.what () << std::endl; |
|---|
| 60 | } |
|---|
| 61 | } |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | template<class T> |
|---|
| 65 | void peak<T>::operator () (int runs) { |
|---|
| 66 | header ("peak"); |
|---|
| 67 | |
|---|
| 68 | header ("plus"); |
|---|
| 69 | peak_c_plus<T> () (runs); |
|---|
| 70 | |
|---|
| 71 | header ("multiplies"); |
|---|
| 72 | peak_c_multiplies<T> () (runs); |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | template struct peak<boost::numeric::interval<float> >; |
|---|
| 76 | template struct peak<boost::numeric::interval<double> >; |
|---|
| 77 | |
|---|
| 78 | #ifdef USE_BOOST_COMPLEX |
|---|
| 79 | |
|---|
| 80 | template struct peak<boost::complex<boost::numeric::interval<float> > >; |
|---|
| 81 | template struct peak<boost::complex<boost::numeric::interval<double> > >; |
|---|
| 82 | |
|---|
| 83 | #endif |
|---|
| 84 | |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | template <typename scalar> |
|---|
| 88 | void do_bench (std::string type_string, int scale) |
|---|
| 89 | { |
|---|
| 90 | header (type_string); |
|---|
| 91 | peak<scalar> () (1000000 * scale); |
|---|
| 92 | |
|---|
| 93 | header (type_string + ", 3"); |
|---|
| 94 | bench_1<scalar, 3> () (1000000 * scale); |
|---|
| 95 | bench_2<scalar, 3> () (300000 * scale); |
|---|
| 96 | bench_3<scalar, 3> () (100000 * scale); |
|---|
| 97 | |
|---|
| 98 | header (type_string + ", 10"); |
|---|
| 99 | bench_1<scalar, 10> () (300000 * scale); |
|---|
| 100 | bench_2<scalar, 10> () (30000 * scale); |
|---|
| 101 | bench_3<scalar, 10> () (3000 * scale); |
|---|
| 102 | |
|---|
| 103 | header (type_string + ", 30"); |
|---|
| 104 | bench_1<scalar, 30> () (100000 * scale); |
|---|
| 105 | bench_2<scalar, 30> () (3000 * scale); |
|---|
| 106 | bench_3<scalar, 30> () (100 * scale); |
|---|
| 107 | |
|---|
| 108 | header (type_string + ", 100"); |
|---|
| 109 | bench_1<scalar, 100> () (30000 * scale); |
|---|
| 110 | bench_2<scalar, 100> () (300 * scale); |
|---|
| 111 | bench_3<scalar, 100> () (3 * scale); |
|---|
| 112 | } |
|---|
| 113 | |
|---|
| 114 | int main (int argc, char *argv []) { |
|---|
| 115 | |
|---|
| 116 | int scale = 1; |
|---|
| 117 | if (argc > 1) |
|---|
| 118 | scale = std::atoi (argv [1]); |
|---|
| 119 | |
|---|
| 120 | #ifdef USE_FLOAT |
|---|
| 121 | do_bench<boost::numeric::interval<float> > ("boost::numeric::interval<FLOAT>", scale); |
|---|
| 122 | #endif |
|---|
| 123 | |
|---|
| 124 | #ifdef USE_DOUBLE |
|---|
| 125 | do_bench<boost::numeric::interval<double> > ("boost::numeric::interval<DOUBLE>", scale); |
|---|
| 126 | #endif |
|---|
| 127 | |
|---|
| 128 | #ifdef USE_STD_COMPLEX |
|---|
| 129 | #ifdef USE_FLOAT |
|---|
| 130 | do_bench<std::complex<boost::numeric::interval<float> > > ("boost::numeric::interval<COMPLEX<FLOAT>>", scale); |
|---|
| 131 | #endif |
|---|
| 132 | |
|---|
| 133 | #ifdef USE_DOUBLE |
|---|
| 134 | do_bench<std::complex<doublboost::numeric::interval<double> > > ("boost::numeric::interval<COMPLEX<DOUBLE>>", scale); |
|---|
| 135 | #endif |
|---|
| 136 | #endif |
|---|
| 137 | |
|---|
| 138 | return 0; |
|---|
| 139 | } |
|---|