From 15c71232fa04aae86e4b52da654ff0ee6b4771ce Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Sun, 23 Feb 2020 15:10:54 +0100 Subject: [PATCH] Adjust FFT benchmark to use same data in each iteration. --- app/benchmark_fft/main.cpp | 9 ++++++--- extern/benchmark_base/include/benchmark_base/fft.h | 2 +- extern/benchmark_base/src/fft.cpp | 15 +++------------ extern/benchmark_runner/benchmark_runner.h | 11 ++++++++--- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/app/benchmark_fft/main.cpp b/app/benchmark_fft/main.cpp index cbd5fb9..aa5dc06 100644 --- a/app/benchmark_fft/main.cpp +++ b/app/benchmark_fft/main.cpp @@ -43,8 +43,9 @@ int main(int argc, char **argv) { string full_directory = directory + "/PLS_v3/"; benchmark_runner runner{full_directory, test_name}; - fft::complex_vector data = fft::generate_input(); - fft::complex_vector swap_array(data.size()); + fft::complex_vector data(fft::SIZE); + fft::complex_vector swap_array(fft::SIZE); + fft::fill_input(data); static_scheduler_memory> complex_vector; -complex_vector generate_input(); +void fill_input(fft::complex_vector &data); void divide(complex_vector::iterator data, complex_vector::iterator swap_array, int n); void conquer(complex_vector::iterator data, complex_vector::iterator swap_array, int n); diff --git a/extern/benchmark_base/src/fft.cpp b/extern/benchmark_base/src/fft.cpp index 95f6a64..d21d00c 100644 --- a/extern/benchmark_base/src/fft.cpp +++ b/extern/benchmark_base/src/fft.cpp @@ -4,19 +4,10 @@ namespace comparison_benchmarks { namespace base { namespace fft { -complex_vector generate_input() { - std::vector known_frequencies{2, 11, 52, 88, 256}; - fft::complex_vector data(SIZE); - // Set our input data to match a time series of the known_frequencies. - // When applying fft to this time-series we should find these frequencies. - for (int i = 0; i < SIZE; i++) { - data[i] = std::complex(0.0, 0.0); - for (auto frequencie : known_frequencies) { - data[i] += sin(2 * M_PI * frequencie * i / SIZE); - } +void fill_input(fft::complex_vector &data) { + for (size_t i = 0; i < data.size(); i++) { + data[i] = std::complex(sin(i), 0.0); } - - return data; } void divide(complex_vector::iterator data, complex_vector::iterator tmp_odd_elements, int n) { diff --git a/extern/benchmark_runner/benchmark_runner.h b/extern/benchmark_runner/benchmark_runner.h index b10b84e..7a9ef2b 100644 --- a/extern/benchmark_runner/benchmark_runner.h +++ b/extern/benchmark_runner/benchmark_runner.h @@ -65,14 +65,19 @@ class benchmark_runner { times_.emplace_back(time); } - void run_iterations(int count, function f, int warmup_count) { + void run_iterations(int count, + const function measure, + int warmup_count, + const function prepare = []() {}) { for (int i = 0; i < warmup_count; i++) { - f(); + prepare(); + measure(); } for (int i = 0; i < count; i++) { + prepare(); start_iteration(); - f(); + measure(); end_iteration(); } } -- libgit2 0.26.0