From 7757bf0b6c4de60befc85e623e27d6fa48ba7004 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Fri, 2 Feb 2024 16:25:56 -0500 Subject: [PATCH 1/2] Add fftw3 to benchmark script --- benches/benchmark.sh | 18 +++++++++++++++--- benches/main.c | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/benches/benchmark.sh b/benches/benchmark.sh index 130da81..e234ece 100644 --- a/benches/benchmark.sh +++ b/benches/benchmark.sh @@ -15,11 +15,22 @@ iters=$3 OUTPUT_DIR=benchmark-data.$(date +"%Y.%m.%d.%H-%M-%S") mkdir -p "$OUTPUT_DIR"/fftw3 && mkdir "$OUTPUT_DIR"/rustfft && mkdir "$OUTPUT_DIR"/phastft +benchmark_fftw3() { + make clean && make + + for n in $(seq "$start" "$end"); do + echo "Running FFTW3 benchmark for N = 2^${n}..." && \ + for _ in $(seq 1 "$iters"); do + ./bench_fftw "${n}" >> "${OUTPUT_DIR}"/fftw3/size_"${n}" + done + done +} + benchmark_phastft() { cargo clean && cargo build --release --examples for n in $(seq "$start" "$end"); do - echo "running PhastFT benchmark for N = 2^${n}" && \ + echo "Running PhastFT benchmark for N = 2^${n}..." && \ for _ in $(seq 1 "$iters"); do ../target/release/examples/benchmark "${n}" >> "${OUTPUT_DIR}"/phastft/size_"${n}" done @@ -30,12 +41,13 @@ benchmark_rustfft() { cargo clean && cargo build --release --examples for n in $(seq "$start" "$end"); do - echo "running RustFFT benchmark for N = 2^${n}" && \ + echo "Running RustFFT benchmark for N = 2^${n}..." && \ for _ in $(seq 1 "$iters"); do ../target/release/examples/rustfft "${n}" >> "${OUTPUT_DIR}"/rustfft/size_"${n}" done done } +benchmark_fftw3 +benchmark_phastft benchmark_rustfft -benchmark_phastft \ No newline at end of file diff --git a/benches/main.c b/benches/main.c index a7b96f7..ac97c06 100644 --- a/benches/main.c +++ b/benches/main.c @@ -24,8 +24,8 @@ int main(int argc, char** argv) { 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); From 7a77829046d0861668c2812859ed1e1b2b53dbcd Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Fri, 2 Feb 2024 16:44:32 -0500 Subject: [PATCH 2/2] Fix typos in benchmarking code --- benches/Makefile | 4 ++-- examples/benchmark.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benches/Makefile b/benches/Makefile index ca80722..6cf7f13 100644 --- a/benches/Makefile +++ b/benches/Makefile @@ -2,9 +2,9 @@ CC = gcc CFLAGS = -Wall -Wextra -O3 -march=native LIBS = -lfftw3 -lm -program: main.c +bench_fftw: main.c $(CC) $(CFLAGS) -o bench_fftw main.c $(LIBS) clean: - rm -f program + rm -f bench_fftw diff --git a/examples/benchmark.rs b/examples/benchmark.rs index 52bc0cc..e00bb78 100644 --- a/examples/benchmark.rs +++ b/examples/benchmark.rs @@ -10,10 +10,10 @@ fn benchmark_fft(n: usize) { let mut imags = vec![0.0; big_n]; gen_random_signal(&mut reals, &mut imags); - // let now = std::time::Instant::now(); + let now = std::time::Instant::now(); fft_dif(&mut reals, &mut imags); - // let elapsed = now.elapsed().as_micros(); - // println!("{elapsed}"); + let elapsed = now.elapsed().as_micros(); + println!("{elapsed}"); } fn main() {