mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Migrate Eigen benchmarks to the Google benchmark framework
libeigen/eigen!2132 Closes #3025 Co-authored-by: Rasmus Munk Larsen <rmlarsen@gmail.com>
This commit is contained in:
43
benchmarks/benchFFT.cpp
Normal file
43
benchmarks/benchFFT.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <Eigen/Core>
|
||||
#include <unsupported/Eigen/FFT>
|
||||
#include <complex>
|
||||
#include <vector>
|
||||
|
||||
using namespace Eigen;
|
||||
|
||||
template <typename T, bool Forward, bool Unscaled = false, bool HalfSpec = false>
|
||||
static void BM_FFT(benchmark::State& state) {
|
||||
typedef typename NumTraits<T>::Real ScalarType;
|
||||
typedef std::complex<ScalarType> Complex;
|
||||
int nfft = state.range(0);
|
||||
std::vector<T> inbuf(nfft);
|
||||
std::vector<Complex> outbuf(nfft);
|
||||
FFT<ScalarType> fft;
|
||||
if (Unscaled) fft.SetFlag(fft.Unscaled);
|
||||
if (HalfSpec) fft.SetFlag(fft.HalfSpectrum);
|
||||
std::fill(inbuf.begin(), inbuf.end(), T(0));
|
||||
fft.fwd(outbuf, inbuf);
|
||||
|
||||
for (auto _ : state) {
|
||||
if (Forward)
|
||||
fft.fwd(outbuf, inbuf);
|
||||
else
|
||||
fft.inv(inbuf, outbuf);
|
||||
benchmark::DoNotOptimize(outbuf.data());
|
||||
benchmark::DoNotOptimize(inbuf.data());
|
||||
}
|
||||
double mflops_per_iter = 5.0 * nfft * std::log2(static_cast<double>(nfft));
|
||||
if (!NumTraits<T>::IsComplex) mflops_per_iter /= 2;
|
||||
state.counters["MFLOPS"] =
|
||||
benchmark::Counter(mflops_per_iter, benchmark::Counter::kIsIterationInvariantRate, benchmark::Counter::kIs1000);
|
||||
}
|
||||
|
||||
BENCHMARK(BM_FFT<std::complex<float>, true>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<std::complex<float>, false>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<float, true>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<float, false>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<std::complex<double>, true>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<std::complex<double>, false>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<double, true>)->Arg(1024)->Arg(4096);
|
||||
BENCHMARK(BM_FFT<double, false>)->Arg(1024)->Arg(4096);
|
||||
Reference in New Issue
Block a user