Skip to content

Commit

Permalink
Add FFTW3 benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Feb 2, 2024
1 parent f2efeff commit 3173385
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
10 changes: 10 additions & 0 deletions benches/Makefile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion benches/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Benchmarking
# BENCHMARKING
36 changes: 36 additions & 0 deletions benches/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdlib.h>
#include <math.h>
#include <fftw3.h>
#include <time.h>

int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s <n>\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;
}

0 comments on commit 3173385

Please sign in to comment.