| 1 | /*****************************************************************************
|
|---|
| 2 |
|
|---|
| 3 | TestSpeed.hpp
|
|---|
| 4 | Copyright (c) 2005 Laurent de Soras
|
|---|
| 5 |
|
|---|
| 6 | --- Legal stuff ---
|
|---|
| 7 |
|
|---|
| 8 | This library is free software; you can redistribute it and/or
|
|---|
| 9 | modify it under the terms of the GNU Lesser General Public
|
|---|
| 10 | License as published by the Free Software Foundation; either
|
|---|
| 11 | version 2.1 of the License, or (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This library is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 16 | Lesser General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU Lesser General Public
|
|---|
| 19 | License along with this library; if not, write to the Free Software
|
|---|
| 20 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 21 |
|
|---|
| 22 | *Tab=3***********************************************************************/
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 | #if defined (TestSpeed_CURRENT_CODEHEADER)
|
|---|
| 27 | #error Recursive inclusion of TestSpeed code header.
|
|---|
| 28 | #endif
|
|---|
| 29 | #define TestSpeed_CURRENT_CODEHEADER
|
|---|
| 30 |
|
|---|
| 31 | #if ! defined (TestSpeed_CODEHEADER_INCLUDED)
|
|---|
| 32 | #define TestSpeed_CODEHEADER_INCLUDED
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
|
|---|
| 37 |
|
|---|
| 38 | #include "test_fnc.h"
|
|---|
| 39 | #include "stopwatch/StopWatch.h"
|
|---|
| 40 | #include "TestWhiteNoiseGen.h"
|
|---|
| 41 |
|
|---|
| 42 | #include <typeinfo>
|
|---|
| 43 |
|
|---|
| 44 | #include <cstdio>
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 | template <class FO>
|
|---|
| 53 | int TestSpeed <FO>::perform_test_single_object (FO &fft)
|
|---|
| 54 | {
|
|---|
| 55 | assert (&fft != 0);
|
|---|
| 56 |
|
|---|
| 57 | int ret_val = 0;
|
|---|
| 58 |
|
|---|
| 59 | const std::type_info & ti = typeid (fft);
|
|---|
| 60 | const char * class_name_0 = ti.name ();
|
|---|
| 61 |
|
|---|
| 62 | if (ret_val == 0)
|
|---|
| 63 | {
|
|---|
| 64 | perform_test_d (fft, class_name_0);
|
|---|
| 65 | }
|
|---|
| 66 | if (ret_val == 0)
|
|---|
| 67 | {
|
|---|
| 68 | perform_test_i (fft, class_name_0);
|
|---|
| 69 | }
|
|---|
| 70 | if (ret_val == 0)
|
|---|
| 71 | {
|
|---|
| 72 | perform_test_di (fft, class_name_0);
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | if (ret_val == 0)
|
|---|
| 76 | {
|
|---|
| 77 | printf ("\n");
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | return (ret_val);
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 | template <class FO>
|
|---|
| 86 | int TestSpeed <FO>::perform_test_d (FO &fft, const char *class_name_0)
|
|---|
| 87 | {
|
|---|
| 88 | assert (&fft != 0);
|
|---|
| 89 | assert (class_name_0 != 0);
|
|---|
| 90 |
|
|---|
| 91 | const long len = fft.get_length ();
|
|---|
| 92 | const long nbr_tests = limit (
|
|---|
| 93 | static_cast <long> (NBR_SPD_TESTS / len / len),
|
|---|
| 94 | 1L,
|
|---|
| 95 | static_cast <long> (MAX_NBR_TESTS)
|
|---|
| 96 | );
|
|---|
| 97 |
|
|---|
| 98 | TestWhiteNoiseGen <DataType> noise;
|
|---|
| 99 | std::vector <DataType> x (len, 0);
|
|---|
| 100 | std::vector <DataType> s (len);
|
|---|
| 101 | noise.generate (&x [0], len);
|
|---|
| 102 |
|
|---|
| 103 | printf (
|
|---|
| 104 | "%s::do_fft () speed test [%ld samples]... ",
|
|---|
| 105 | class_name_0,
|
|---|
| 106 | len
|
|---|
| 107 | );
|
|---|
| 108 | fflush (stdout);
|
|---|
| 109 |
|
|---|
| 110 | stopwatch::StopWatch chrono;
|
|---|
| 111 | chrono.start ();
|
|---|
| 112 | for (long test = 0; test < nbr_tests; ++ test)
|
|---|
| 113 | {
|
|---|
| 114 | fft.do_fft (&s [0], &x [0]);
|
|---|
| 115 | chrono.stop_lap ();
|
|---|
| 116 | }
|
|---|
| 117 |
|
|---|
| 118 | printf ("%.1f clocks/sample\n", chrono.get_time_best_lap (len));
|
|---|
| 119 |
|
|---|
| 120 | return (0);
|
|---|
| 121 | }
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 | template <class FO>
|
|---|
| 126 | int TestSpeed <FO>::perform_test_i (FO &fft, const char *class_name_0)
|
|---|
| 127 | {
|
|---|
| 128 | assert (&fft != 0);
|
|---|
| 129 | assert (class_name_0 != 0);
|
|---|
| 130 |
|
|---|
| 131 | const long len = fft.get_length ();
|
|---|
| 132 | const long nbr_tests = limit (
|
|---|
| 133 | static_cast <long> (NBR_SPD_TESTS / len / len),
|
|---|
| 134 | 1L,
|
|---|
| 135 | static_cast <long> (MAX_NBR_TESTS)
|
|---|
| 136 | );
|
|---|
| 137 |
|
|---|
| 138 | TestWhiteNoiseGen <DataType> noise;
|
|---|
| 139 | std::vector <DataType> x (len);
|
|---|
| 140 | std::vector <DataType> s (len, 0);
|
|---|
| 141 | noise.generate (&s [0], len);
|
|---|
| 142 |
|
|---|
| 143 | printf (
|
|---|
| 144 | "%s::do_ifft () speed test [%ld samples]... ",
|
|---|
| 145 | class_name_0,
|
|---|
| 146 | len
|
|---|
| 147 | );
|
|---|
| 148 | fflush (stdout);
|
|---|
| 149 |
|
|---|
| 150 | stopwatch::StopWatch chrono;
|
|---|
| 151 | chrono.start ();
|
|---|
| 152 | for (long test = 0; test < nbr_tests; ++ test)
|
|---|
| 153 | {
|
|---|
| 154 | fft.do_ifft (&s [0], &x [0]);
|
|---|
| 155 | chrono.stop_lap ();
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | printf ("%.1f clocks/sample\n", chrono.get_time_best_lap (len));
|
|---|
| 159 |
|
|---|
| 160 | return (0);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 |
|
|---|
| 164 |
|
|---|
| 165 | template <class FO>
|
|---|
| 166 | int TestSpeed <FO>::perform_test_di (FO &fft, const char *class_name_0)
|
|---|
| 167 | {
|
|---|
| 168 | assert (&fft != 0);
|
|---|
| 169 | assert (class_name_0 != 0);
|
|---|
| 170 |
|
|---|
| 171 | const long len = fft.get_length ();
|
|---|
| 172 | const long nbr_tests = limit (
|
|---|
| 173 | static_cast <long> (NBR_SPD_TESTS / len / len),
|
|---|
| 174 | 1L,
|
|---|
| 175 | static_cast <long> (MAX_NBR_TESTS)
|
|---|
| 176 | );
|
|---|
| 177 |
|
|---|
| 178 | TestWhiteNoiseGen <DataType> noise;
|
|---|
| 179 | std::vector <DataType> x (len, 0);
|
|---|
| 180 | std::vector <DataType> s (len);
|
|---|
| 181 | std::vector <DataType> y (len);
|
|---|
| 182 | noise.generate (&x [0], len);
|
|---|
| 183 |
|
|---|
| 184 | printf (
|
|---|
| 185 | "%s::do_fft () / do_ifft () / rescale () speed test [%ld samples]... ",
|
|---|
| 186 | class_name_0,
|
|---|
| 187 | len
|
|---|
| 188 | );
|
|---|
| 189 | fflush (stdout);
|
|---|
| 190 |
|
|---|
| 191 | stopwatch::StopWatch chrono;
|
|---|
| 192 |
|
|---|
| 193 | chrono.start ();
|
|---|
| 194 | for (long test = 0; test < nbr_tests; ++ test)
|
|---|
| 195 | {
|
|---|
| 196 | fft.do_fft (&s [0], &x [0]);
|
|---|
| 197 | fft.do_ifft (&s [0], &y [0]);
|
|---|
| 198 | fft.rescale (&y [0]);
|
|---|
| 199 | chrono.stop_lap ();
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | printf ("%.1f clocks/sample\n", chrono.get_time_best_lap (len));
|
|---|
| 203 |
|
|---|
| 204 | return (0);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
|
|---|
| 209 | /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
|
|---|
| 210 |
|
|---|
| 211 |
|
|---|
| 212 |
|
|---|
| 213 | /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
|
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
|
|---|
| 217 | #endif // TestSpeed_CODEHEADER_INCLUDED
|
|---|
| 218 |
|
|---|
| 219 | #undef TestSpeed_CURRENT_CODEHEADER
|
|---|
| 220 |
|
|---|
| 221 |
|
|---|
| 222 |
|
|---|
| 223 | /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
|
|---|