mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-01-17 12:43:01 +00:00
Test FFT with random numbers instead of all zeros
This commit is contained in:
parent
6f5f8e8948
commit
1ac986e207
@ -29,7 +29,10 @@
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <random>
|
||||
#include <gnuradio/fft/fft.h>
|
||||
|
||||
|
||||
@ -37,18 +40,31 @@ DEFINE_int32(fft_iterations_test, 1000, "Number of averaged iterations in FFT le
|
||||
|
||||
TEST(FFTLengthTest, MeasureExecutionTime)
|
||||
{
|
||||
unsigned int d_fft_size;
|
||||
unsigned int fft_sizes [] = { 1000, 1024, 1960, 2000, 2048, 4000, 4096, 4725, 5000, 8000, 8192, 10368, 12000, 16000, 16384, 27000, 32768, 50000, 65536 };
|
||||
|
||||
std::chrono::time_point<std::chrono::system_clock> start, end;
|
||||
|
||||
unsigned int fft_sizes [18] = { 1000, 1024, 1960, 2000, 2048, 4000, 4096, 4725, 8000, 8192, 10368, 12000, 16000, 16384, 27000, 32768, 50000, 65536 };
|
||||
double execution_times [18];
|
||||
std::random_device r;
|
||||
std::default_random_engine e1(r());
|
||||
std::default_random_engine e2(r());
|
||||
std::uniform_real_distribution<float> uniform_dist(-1, 1);
|
||||
auto func = [] (float a, float b) { return gr_complex(a, b); }; // Helper lambda function that returns a gr_complex
|
||||
auto random_number1 = std::bind(uniform_dist, e1);
|
||||
auto random_number2 = std::bind(uniform_dist, e2);
|
||||
auto gen = std::bind(func, random_number1, random_number2); // Function that returns a random gr_complex
|
||||
|
||||
std::vector<unsigned int> fft_sizes_v(fft_sizes, fft_sizes + sizeof(fft_sizes) / sizeof(unsigned int) );
|
||||
std::vector<unsigned int>::const_iterator it;
|
||||
unsigned int d_fft_size;
|
||||
|
||||
EXPECT_NO_THROW(
|
||||
for(int i = 0; i < 18; i++)
|
||||
for(it = fft_sizes_v.cbegin(); it != fft_sizes_v.cend(); ++it)
|
||||
{
|
||||
gr::fft::fft_complex* d_fft;
|
||||
d_fft_size = fft_sizes[i];
|
||||
d_fft_size = *it;
|
||||
d_fft = new gr::fft::fft_complex(d_fft_size, true);
|
||||
std::fill_n( d_fft->get_inbuf(), d_fft_size, gr_complex( 0.0, 0.0 ) );
|
||||
|
||||
std::generate_n( d_fft->get_inbuf(), d_fft_size, gen );
|
||||
|
||||
start = std::chrono::system_clock::now();
|
||||
for(int k = 0; k < FLAGS_fft_iterations_test; k++)
|
||||
@ -57,8 +73,8 @@ TEST(FFTLengthTest, MeasureExecutionTime)
|
||||
}
|
||||
end = std::chrono::system_clock::now();
|
||||
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||
execution_times[i] = elapsed_seconds.count() / static_cast<double>(FLAGS_fft_iterations_test);
|
||||
std::cout << "FFT execution time for length=" << d_fft_size << " : " << execution_times[i] << " [s]" << std::endl;
|
||||
double execution_time = elapsed_seconds.count() / static_cast<double>(FLAGS_fft_iterations_test);
|
||||
std::cout << "FFT execution time for length=" << d_fft_size << " : " << execution_time << " [s]" << std::endl;
|
||||
delete d_fft;
|
||||
}
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user