From 86fe863673ae3021a65327a2d6c7aae0216e8dd2 Mon Sep 17 00:00:00 2001 From: "E. G. Patrick Bos" Date: Mon, 16 Oct 2017 17:23:33 +0200 Subject: [PATCH] Added benchmarks: real 2D and nD with n = 1,2 (#13) Results on my laptop: they perform exactly the same! That means we could get rid of all the special 1, 2 and 3 dimensional functions, which will clear up the code a lot. --- bench/basic_interface.cpp | 70 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/bench/basic_interface.cpp b/bench/basic_interface.cpp index 7a5c3cf..9a84518 100644 --- a/bench/basic_interface.cpp +++ b/bench/basic_interface.cpp @@ -27,16 +27,20 @@ auto generate_data(std::size_t n) { return xt::random::rand(shape, 0, std::numeric_limits::max() / std::pow(n, dim)); } +//// +// Real FFT: 1D +//// + template class rfft1Dxarray : public ::benchmark::Fixture { public: void SetUp(const ::benchmark::State& state) { - data_size = 4; + data_size = 1024; a = generate_data(data_size); // let fftw accumulate wisdom - auto b = xt::fftw::rfft(a); - auto c = xt::fftw::irfft(b); +// auto b = xt::fftw::rfft(a); // DOES NOT HAVE ANY NOTICEABLE EFFECT... +// auto c = xt::fftw::irfft(b); } void TearDown(const ::benchmark::State& /*state*/) {} @@ -56,4 +60,64 @@ BENCHMARK_F(rfft1Dxarray_float, TransformAndInvert)(::benchmark::State& st) { } } +//// +// Real FFT: nD with n = 1 +//// + +BENCHMARK_F(rfft1Dxarray_float, TransformAndInvert_nD)(::benchmark::State& st) { + while (st.KeepRunning()) { + auto a_fourier = xt::fftw::rfftn<1>(a); + ::benchmark::DoNotOptimize(a_fourier); + auto should_be_a = xt::fftw::irfftn<1>(a_fourier); + ::benchmark::DoNotOptimize(should_be_a); + } +} + +//// +// Real FFT: 2D +//// + +template +class rfft2Dxarray : public ::benchmark::Fixture { +public: + void SetUp(const ::benchmark::State& state) { + data_size = 64; + a = generate_data(data_size); + + // let fftw accumulate wisdom +// auto b = xt::fftw::rfft(a); // DOES NOT HAVE ANY NOTICEABLE EFFECT... +// auto c = xt::fftw::irfft(b); + } + + void TearDown(const ::benchmark::State& /*state*/) {} + + std::size_t data_size; + xt::xarray a; +}; + +using rfft2Dxarray_float = rfft2Dxarray; + +BENCHMARK_F(rfft2Dxarray_float, TransformAndInvert)(::benchmark::State& st) { + while (st.KeepRunning()) { + auto a_fourier = xt::fftw::rfft2(a); + ::benchmark::DoNotOptimize(a_fourier); + auto should_be_a = xt::fftw::irfft2(a_fourier); + ::benchmark::DoNotOptimize(should_be_a); + } +} + +//// +// Real FFT: nD with n = 2 +//// + +BENCHMARK_F(rfft2Dxarray_float, TransformAndInvert_nD)(::benchmark::State& st) { + while (st.KeepRunning()) { + auto a_fourier = xt::fftw::rfftn<2>(a); + ::benchmark::DoNotOptimize(a_fourier); + auto should_be_a = xt::fftw::irfftn<2>(a_fourier); + ::benchmark::DoNotOptimize(should_be_a); + } +} + + BENCHMARK_MAIN()