diff --git a/benches/Makefile b/benches/Makefile new file mode 100644 index 0000000..ca80722 --- /dev/null +++ b/benches/Makefile @@ -0,0 +1,10 @@ +CC = gcc +CFLAGS = -Wall -Wextra -O3 -march=native +LIBS = -lfftw3 -lm + +program: main.c + $(CC) $(CFLAGS) -o bench_fftw main.c $(LIBS) + +clean: + rm -f program + diff --git a/benches/README.md b/benches/README.md index 4552684..bee5c18 100644 --- a/benches/README.md +++ b/benches/README.md @@ -1 +1 @@ -Benchmarking +# BENCHMARKING diff --git a/benches/main.c b/benches/main.c new file mode 100644 index 0000000..a7b96f7 --- /dev/null +++ b/benches/main.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +int main(int argc, char** argv) { + if (argc != 2) { + fprintf(stderr, "Usage: %s \n", argv[0]); + return EXIT_FAILURE; + } + long n = strtol(argv[1], NULL, 0); + printf("%ld\n", n); + + int N = 1 << n; + fftw_complex* in = fftw_alloc_complex(N); + + double a = 1.0; + for (int i = 0; i < N; i++) { + in[i][0] = ((double)rand()/(double)(RAND_MAX)) * a; + in[i][1] = ((double)rand()/(double)(RAND_MAX)) * a; + } + + double tic = clock(); + fftw_plan p = fftw_plan_dft_1d(N, in, in, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_execute(p); + double toc = clock(); + + double elapsed = ((double)(toc - tic) / CLOCKS_PER_SEC) * 1000000; + printf("%f\n", elapsed); + fftw_free(in); + fftw_destroy_plan(p); + fftw_cleanup(); + + return EXIT_SUCCESS; +} +