SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
mainbench.cpp
Go to the documentation of this file.
1 // Copyright (C) 2018 Edouard Griffiths, F4EXB. //
3 // //
4 // Swagger server adapter interface //
5 // //
6 // This program is free software; you can redistribute it and/or modify //
7 // it under the terms of the GNU General Public License as published by //
8 // the Free Software Foundation as version 3 of the License, or //
9 // (at your option) any later version. //
10 // //
11 // This program is distributed in the hope that it will be useful, //
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
14 // GNU General Public License V3 for more details. //
15 // //
16 // You should have received a copy of the GNU General Public License //
17 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
19 
20 #include <QDebug>
21 #include <QElapsedTimer>
22 
23 #include "ambe/ambeengine.h"
24 
25 #include "mainbench.h"
26 
28 
29 MainBench::MainBench(qtwebapp::LoggerWithFile *logger, const ParserBench& parser, QObject *parent) :
30  QObject(parent),
31  m_logger(logger),
32  m_parser(parser),
33  m_uniform_distribution_f(-1.0, 1.0),
34  m_uniform_distribution_s16(-2048, 2047)
35 {
36  qDebug() << "MainBench::MainBench: start";
37  m_instance = this;
38  qDebug() << "MainBench::MainBench: end";
39 }
40 
42 {}
43 
45 {
46  qDebug() << "MainBench::run: parameters:"
47  << " testStr: " << m_parser.getTestStr()
48  << " testType: " << (int) m_parser.getTestType()
49  << " nsamples: " << m_parser.getNbSamples()
50  << " repet: " << m_parser.getRepetition()
51  << " log2f: " << m_parser.getLog2Factor();
52 
65  } else if (m_parser.getTestType() == ParserBench::TestAMBE) {
66  testAMBE();
67  } else {
68  qDebug() << "MainBench::run: unknown test type: " << m_parser.getTestType();
69  }
70 
71  emit finished();
72 }
73 
75 {
76  QElapsedTimer timer;
77  qint64 nsecs = 0;
78 
79  qDebug() << "MainBench::testDecimateII: create test data";
80 
81  qint16 *buf = new qint16[m_parser.getNbSamples()*2];
83  auto my_rand = std::bind(m_uniform_distribution_s16, m_generator);
84  std::generate(buf, buf + m_parser.getNbSamples()*2 - 1, my_rand);
85 
86  qDebug() << "MainBench::testDecimateII: run test";
87 
88  for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
89  {
90  switch (testType)
91  {
93  timer.start();
95  nsecs += timer.nsecsElapsed();
96  break;
98  timer.start();
100  nsecs += timer.nsecsElapsed();
101  break;
103  default:
104  timer.start();
105  decimateII(buf, m_parser.getNbSamples()*2);
106  nsecs += timer.nsecsElapsed();
107  break;
108  }
109  }
110 
111  printResults("MainBench::testDecimateII", nsecs);
112 
113  qDebug() << "MainBench::testDecimateII: cleanup test data";
114  delete[] buf;
115 }
116 
118 {
119  QElapsedTimer timer;
120  qint64 nsecs = 0;
121 
122  qDebug() << "MainBench::testDecimateIF: create test data";
123 
124  qint16 *buf = new qint16[m_parser.getNbSamples()*2];
126  auto my_rand = std::bind(m_uniform_distribution_s16, m_generator);
127  std::generate(buf, buf + m_parser.getNbSamples()*2 - 1, my_rand);
128 
129  qDebug() << "MainBench::testDecimateIF: run test";
130 
131  for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
132  {
133  timer.start();
134  decimateIF(buf, m_parser.getNbSamples()*2);
135  nsecs += timer.nsecsElapsed();
136  }
137 
138  printResults("MainBench::testDecimateIF", nsecs);
139 
140  qDebug() << "MainBench::testDecimateIF: cleanup test data";
141  delete[] buf;
142 }
143 
145 {
146  QElapsedTimer timer;
147  qint64 nsecs = 0;
148 
149  qDebug() << "MainBench::testDecimateFI: create test data";
150 
151  float *buf = new float[m_parser.getNbSamples()*2];
153  auto my_rand = std::bind(m_uniform_distribution_f, m_generator);
154  std::generate(buf, buf + m_parser.getNbSamples()*2 - 1, my_rand); // make sure data is in [-1.0..1.0] range
155 
156  qDebug() << "MainBench::testDecimateFI: run test";
157 
158  for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
159  {
160  timer.start();
161  decimateFI(buf, m_parser.getNbSamples()*2);
162  nsecs += timer.nsecsElapsed();
163  }
164 
165  printResults("MainBench::testDecimateFI", nsecs);
166 
167  qDebug() << "MainBench::testDecimateFI: cleanup test data";
168  delete[] buf;
169 }
170 
172 {
173  QElapsedTimer timer;
174  qint64 nsecs = 0;
175 
176  qDebug() << "MainBench::testDecimateFF: create test data";
177 
178  float *buf = new float[m_parser.getNbSamples()*2];
180  auto my_rand = std::bind(m_uniform_distribution_f, m_generator);
181  std::generate(buf, buf + m_parser.getNbSamples()*2 - 1, my_rand); // make sure data is in [-1.0..1.0] range
182 
183  qDebug() << "MainBench::testDecimateFF: run test";
184 
185  for (uint32_t i = 0; i < m_parser.getRepetition(); i++)
186  {
187  timer.start();
188  decimateFF(buf, m_parser.getNbSamples()*2);
189  nsecs += timer.nsecsElapsed();
190  }
191 
192  printResults("MainBench::testDecimateFF", nsecs);
193 
194  qDebug() << "MainBench::testDecimateFF: cleanup test data";
195  delete[] buf;
196 }
197 
199 {
200  qDebug() << "MainBench::testAMBE";
201  AMBEEngine ambeEngine;
202  std::vector<QString> ambeDevices;
203  ambeEngine.scan(ambeDevices);
204 
205  for (std::vector<QString>::const_iterator it = ambeDevices.begin(); it != ambeDevices.end(); ++it) {
206  qDebug("MainBench::testAMBE: detected AMBE device %s", qPrintable(*it));
207  }
208 }
209 
210 void MainBench::decimateII(const qint16* buf, int len)
211 {
212  SampleVector::iterator it = m_convertBuffer.begin();
213 
214  switch (m_parser.getLog2Factor())
215  {
216  case 0:
217  m_decimatorsII.decimate1(&it, buf, len);
218  break;
219  case 1:
220  m_decimatorsII.decimate2_cen(&it, buf, len);
221  break;
222  case 2:
223  m_decimatorsII.decimate4_cen(&it, buf, len);
224  break;
225  case 3:
226  m_decimatorsII.decimate8_cen(&it, buf, len);
227  break;
228  case 4:
229  m_decimatorsII.decimate16_cen(&it, buf, len);
230  break;
231  case 5:
232  m_decimatorsII.decimate32_cen(&it, buf, len);
233  break;
234  case 6:
235  m_decimatorsII.decimate64_cen(&it, buf, len);
236  break;
237  default:
238  break;
239  }
240 }
241 
242 void MainBench::decimateInfII(const qint16* buf, int len)
243 {
244  SampleVector::iterator it = m_convertBuffer.begin();
245 
246  switch (m_parser.getLog2Factor())
247  {
248  case 0:
249  m_decimatorsII.decimate1(&it, buf, len);
250  break;
251  case 1:
252  m_decimatorsII.decimate2_inf(&it, buf, len);
253  break;
254  case 2:
255  m_decimatorsII.decimate4_inf(&it, buf, len);
256  break;
257  case 3:
258  m_decimatorsII.decimate8_inf(&it, buf, len);
259  break;
260  case 4:
261  m_decimatorsII.decimate16_inf(&it, buf, len);
262  break;
263  case 5:
264  m_decimatorsII.decimate32_inf(&it, buf, len);
265  break;
266  case 6:
267  m_decimatorsII.decimate64_inf(&it, buf, len);
268  break;
269  default:
270  break;
271  }
272 }
273 
274 void MainBench::decimateSupII(const qint16* buf, int len)
275 {
276  SampleVector::iterator it = m_convertBuffer.begin();
277 
278  switch (m_parser.getLog2Factor())
279  {
280  case 0:
281  m_decimatorsII.decimate1(&it, buf, len);
282  break;
283  case 1:
284  m_decimatorsII.decimate2_sup(&it, buf, len);
285  break;
286  case 2:
287  m_decimatorsII.decimate4_sup(&it, buf, len);
288  break;
289  case 3:
290  m_decimatorsII.decimate8_sup(&it, buf, len);
291  break;
292  case 4:
293  m_decimatorsII.decimate16_sup(&it, buf, len);
294  break;
295  case 5:
296  m_decimatorsII.decimate32_sup(&it, buf, len);
297  break;
298  case 6:
299  m_decimatorsII.decimate64_sup(&it, buf, len);
300  break;
301  default:
302  break;
303  }
304 }
305 
306 void MainBench::decimateIF(const qint16* buf, int len)
307 {
308  FSampleVector::iterator it = m_convertBufferF.begin();
309 
310  switch (m_parser.getLog2Factor())
311  {
312  case 0:
313  m_decimatorsIF.decimate1(&it, buf, len);
314  break;
315  case 1:
316  m_decimatorsIF.decimate2_cen(&it, buf, len);
317  break;
318  case 2:
319  m_decimatorsIF.decimate4_cen(&it, buf, len);
320  break;
321  case 3:
322  m_decimatorsIF.decimate8_cen(&it, buf, len);
323  break;
324  case 4:
325  m_decimatorsIF.decimate16_cen(&it, buf, len);
326  break;
327  case 5:
328  m_decimatorsIF.decimate32_cen(&it, buf, len);
329  break;
330  case 6:
331  m_decimatorsIF.decimate64_cen(&it, buf, len);
332  break;
333  default:
334  break;
335  }
336 }
337 
338 void MainBench::decimateFI(const float *buf, int len)
339 {
340  SampleVector::iterator it = m_convertBuffer.begin();
341 
342  switch (m_parser.getLog2Factor())
343  {
344  case 0:
345  m_decimatorsFI.decimate1(&it, buf, len);
346  break;
347  case 1:
348  m_decimatorsFI.decimate2_cen(&it, buf, len);
349  break;
350  case 2:
351  m_decimatorsFI.decimate4_cen(&it, buf, len);
352  break;
353  case 3:
354  m_decimatorsFI.decimate8_cen(&it, buf, len);
355  break;
356  case 4:
357  m_decimatorsFI.decimate16_cen(&it, buf, len);
358  break;
359  case 5:
360  m_decimatorsFI.decimate32_cen(&it, buf, len);
361  break;
362  case 6:
363  m_decimatorsFI.decimate64_cen(&it, buf, len);
364  break;
365  default:
366  break;
367  }
368 }
369 
370 void MainBench::decimateFF(const float *buf, int len)
371 {
372  FSampleVector::iterator it = m_convertBufferF.begin();
373 
374  switch (m_parser.getLog2Factor())
375  {
376  case 0:
377  m_decimatorsFF.decimate1(&it, buf, len);
378  break;
379  case 1:
380  m_decimatorsFF.decimate2_cen(&it, buf, len);
381  break;
382  case 2:
383  m_decimatorsFF.decimate4_cen(&it, buf, len);
384  break;
385  case 3:
386  m_decimatorsFF.decimate8_cen(&it, buf, len);
387  break;
388  case 4:
389  m_decimatorsFF.decimate16_cen(&it, buf, len);
390  break;
391  case 5:
392  m_decimatorsFF.decimate32_cen(&it, buf, len);
393  break;
394  case 6:
395  m_decimatorsFF.decimate64_cen(&it, buf, len);
396  break;
397  default:
398  break;
399  }
400 }
401 
402 void MainBench::printResults(const QString& prefix, qint64 nsecs)
403 {
404  double ratekSs = (m_parser.getNbSamples()*m_parser.getRepetition() / (double) nsecs) * 1e6;
405  QDebug info = qInfo();
406  info.noquote();
407  info << tr("%1: ran test in %L2 ns - sample rate: %3 kS/s").arg(prefix).arg(nsecs).arg(ratekSs);
408 }
Decimators< qint32, qint16, SDR_RX_SAMP_SZ, 12 > m_decimatorsII
Definition: mainbench.h:71
SampleVector m_convertBuffer
Definition: mainbench.h:76
void decimate2_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:498
void decimate64_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2975
uint32_t getRepetition() const
Definition: parserbench.h:47
void decimate32_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate4_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate64_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:3040
void decimate2_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:526
void decimate2_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:554
void decimate64_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:851
DecimatorsFF m_decimatorsFF
Definition: mainbench.h:74
void decimate8_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:941
void decimate64_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimateSupII(const qint16 *buf, int len)
Definition: mainbench.cpp:274
void decimate64_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2418
void scan(std::vector< QString > &ambeDevices)
Definition: ambeengine.cpp:191
void decimate32_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1592
void decimate32_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1902
DecimatorsFI m_decimatorsFI
Definition: mainbench.h:73
void run()
Definition: mainbench.cpp:44
void decimate32_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimateFF(const float *buf, int len)
Definition: mainbench.cpp:370
unsigned int uint32_t
Definition: rtptypes_win.h:46
void decimate4_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:682
void decimateFI(const float *buf, int len)
Definition: mainbench.cpp:338
void testDecimateII(ParserBench::TestType testType=ParserBench::TestDecimatorsII)
Definition: mainbench.cpp:74
void decimate8_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1057
void decimate16_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate2_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate4_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:201
void decimate1(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:87
uint32_t getLog2Factor() const
Definition: parserbench.h:48
void decimate8_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:825
void decimate16_sup(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1300
void decimate2_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
std::uniform_int_distribution< qint16 > m_uniform_distribution_s16
Definition: mainbench.h:69
void finished()
void testDecimateIF()
Definition: mainbench.cpp:117
int32_t i
Definition: decimators.h:244
const QString & getTestStr() const
Definition: parserbench.h:44
void testDecimateFF()
Definition: mainbench.cpp:171
FSampleVector m_convertBufferF
Definition: mainbench.h:77
MainBench(qtwebapp::LoggerWithFile *logger, const ParserBench &parser, QObject *parent=0)
Definition: mainbench.cpp:29
void decimate4_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void printResults(const QString &prefix, qint64 nsecs)
Definition: mainbench.cpp:402
void decimate4_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:782
void testDecimateFI()
Definition: mainbench.cpp:144
void decimateII(const qint16 *buf, int len)
Definition: mainbench.cpp:210
void decimate8_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:282
void decimate16_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimateInfII(const qint16 *buf, int len)
Definition: mainbench.cpp:242
uint32_t getNbSamples() const
Definition: parserbench.h:46
void decimate4_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:582
void decimateIF(const qint16 *buf, int len)
Definition: mainbench.cpp:306
void decimate8_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void testAMBE()
Definition: mainbench.cpp:198
std::uniform_real_distribution< float > m_uniform_distribution_f
Definition: mainbench.h:68
const ParserBench & m_parser
Definition: mainbench.h:66
void decimate8_cen(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate16_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:394
TestType getTestType() const
std::mt19937 m_generator
Definition: mainbench.h:67
void decimate16_inf(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1117
DecimatorsIF< qint16, 12 > m_decimatorsIF
Definition: mainbench.h:72
static MainBench * m_instance
Definition: mainbench.h:64
void decimate64_cen(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate2_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:144
void decimate32_cen(FSampleVector::iterator *it, const T *buf, qint32 nbIAndQ)
Definition: decimatorsif.h:565
void decimate1(FSampleVector::iterator *it, const float *buf, qint32 nbIAndQ)
void decimate16_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:1483
void decimate32_cen(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:2212
void decimate1(SampleVector::iterator *it, const T *buf, qint32 len)
Definition: decimators.h:462
void decimate1(SampleVector::iterator *it, const float *buf, qint32 nbIAndQ)