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