Commit 15c71232 by FritzFlorian

Adjust FFT benchmark to use same data in each iteration.

parent e0604d1f
Pipeline #1412 failed with stages
in 37 seconds
......@@ -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<MAX_NUM_THREADS,
MAX_NUM_TASKS,
......@@ -55,7 +56,9 @@ int main(int argc, char **argv) {
scheduler.perform_work([&]() {
pls_conquer(data.begin(), swap_array.begin(), fft::SIZE);;
});
}, fft::NUM_WARMUP_ITERATIONS);
}, fft::NUM_WARMUP_ITERATIONS, [&]() {
fft::fill_input(data); // Reset data before each run
});
runner.commit_results(true);
return 0;
......
......@@ -16,7 +16,7 @@ const int NUM_WARMUP_ITERATIONS = 100;
const int RECURSIVE_CUTOFF = 32;
typedef std::vector<std::complex<double>> 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);
......
......@@ -4,19 +4,10 @@ namespace comparison_benchmarks {
namespace base {
namespace fft {
complex_vector generate_input() {
std::vector<double> 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<double>(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<double>(sin(i), 0.0);
}
return data;
}
void divide(complex_vector::iterator data, complex_vector::iterator tmp_odd_elements, int n) {
......
......@@ -65,14 +65,19 @@ class benchmark_runner {
times_.emplace_back(time);
}
void run_iterations(int count, function<void(void)> f, int warmup_count) {
void run_iterations(int count,
const function<void(void)> measure,
int warmup_count,
const function<void(void)> 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();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment