# HG changeset patch # User Chris Cannam # Date 1444249689 -3600 # Node ID 4fa5f3f883a2fb75f78badbb19021d1542b37110 # Parent 9af60df83c6f1e2dacd1f1097a2723558e8ae1ea Add native-code version for comparison diff -r 9af60df83c6f -r 4fa5f3f883a2 fft/native.cpp --- /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 + +#include +#include +#include +#include + +using namespace std; +using namespace breakfastquay; + +int main(int argc, char **argv) +{ + vector 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 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(end - start).count() / times; + + cerr << "for size " << size << ", iterations " << iterations + << ": total = " << total << ", time = " + << ms << " ms (" << (iterations / (ms / 1000.0)) << " itr/sec)" << endl; + } +} +