#include "PGFFT.h"
#include <ctime>
#include <iostream>
#include <cstdlib>

using namespace std;

double GetTime()
{
  timespec ts;

  clock_gettime(CLOCK_MONOTONIC_RAW, &ts);

  // Here are some other clocks, but they are not very useful
  // clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
  // clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);

  return double(ts.tv_sec) + double(ts.tv_nsec)*1e-9; 
}

#define TIME_IT(t, action) \
do { \
   double _t0, _t1; \
   long _iter = 1; \
   long _cnt = 0; \
   do { \
      _t0 = GetTime(); \
      for (long _i = 0; _i < _iter; _i++) { action; _cnt++; } \
      _t1 = GetTime(); \
   } while ( _t1 - _t0 < 3 && (_iter *= 2)); \
   t = (_t1 - _t0)/_iter; \
} while(0)


typedef complex<double> cmplx_t;





int main()
{
   vector<long> nvec = { 28679, 33013, 45551, 32*1024 };

   for (long n: nvec) {

      std::cout << "n=" << n << "\n";

      vector<cmplx_t> v(n);
      for (long i = 0; i < n; i++)
	 v[i] = (rand()%10) - 5;

      vector<cmplx_t> w = v;

      PGFFT pgfft(n);

      double t;
      TIME_IT(t, (v=w, pgfft.apply(&v[0]))); 

      std::cout << t << "\n";
   }
}
