Mercurial > hg > js-dsp-test
changeset 27:4fa5f3f883a2
Add native-code version for comparison
author | Chris Cannam |
---|---|
date | Wed, 07 Oct 2015 21:28:09 +0100 |
parents | 9af60df83c6f |
children | 77fca9c01e46 |
files | fft/native.cpp |
diffstat | 1 files changed, 59 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fft/native.cpp Wed Oct 07 21:28:09 2015 +0100 @@ -0,0 +1,59 @@ + +#include <bqfft/FFT.h> + +#include <vector> +#include <iostream> +#include <cmath> +#include <chrono> + +using namespace std; +using namespace breakfastquay; + +int main(int argc, char **argv) +{ + vector<int> sizes { 512, 2048 }; + + int iterations = 2000; + int times = 100; + + for (auto size: sizes) { + + FFT fft(size); + double total = 0.0; + + auto start = chrono::high_resolution_clock::now(); + + for (int ti = 0; ti < times; ++ti) { + + total = 0.0; + + for (int i = 0; i < iterations; ++i) { + + vector<double> ri(size), ro(size/2+1), io(size/2+1); + for (int j = 0; j < size; ++j) { + ri[j] = (j % 2) / 4.0; + } + + fft.forward(ri.data(), ro.data(), io.data()); + + for (int j = 0; j <= size/2; ++j) { + total += sqrt(ro[j] * ro[j] + io[j] * io[j]); + } + + // synthesise the conjugate half + for (int j = 1; j < size/2; ++j) { + total += sqrt(ro[j] * ro[j] + io[j] * io[j]); + } + } + } + + auto end = chrono::high_resolution_clock::now(); + + double ms = chrono::duration<double, milli>(end - start).count() / times; + + cerr << "for size " << size << ", iterations " << iterations + << ": total = " << total << ", time = " + << ms << " ms (" << (iterations / (ms / 1000.0)) << " itr/sec)" << endl; + } +} +