From d95035ee637e7d69104e76cfb8515c0bece10160 Mon Sep 17 00:00:00 2001 From: Saveliy Yusufov Date: Fri, 9 Feb 2024 11:18:55 -0500 Subject: [PATCH] Fix FFTW benchmark to use wall time --- benches/main.c | 27 +++++++++++++++++++++------ profile.sh | 10 +++++++++- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/benches/main.c b/benches/main.c index ac97c06..f0a2dcc 100644 --- a/benches/main.c +++ b/benches/main.c @@ -2,17 +2,29 @@ #include #include #include +#include // uint64 +#include // clock_gettime + +#define BILLION 1000000000L + 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; + + uint64_t diff1; + struct timespec start, end; + clock_gettime(CLOCK_MONOTONIC, &start); fftw_complex* in = fftw_alloc_complex(N); + fftw_plan p = fftw_plan_dft_1d(N, in, in, FFTW_FORWARD, FFTW_ESTIMATE); + clock_gettime(CLOCK_MONOTONIC, &end); + diff1 = BILLION * (end.tv_sec - start.tv_sec) + end.tv_nsec - start.tv_nsec; double a = 1.0; for (int i = 0; i < N; i++) { @@ -20,13 +32,16 @@ int main(int argc, char** argv) { 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); + uint64_t diff2; + struct timespec start1, end1; + clock_gettime(CLOCK_MONOTONIC, &start1); fftw_execute(p); - double toc = clock(); - double elapsed = ((double)(toc - tic) / CLOCKS_PER_SEC) * 1000000; + clock_gettime(CLOCK_MONOTONIC, &end1); /* mark the end1 time */ + diff2 = BILLION * (end1.tv_sec - start1.tv_sec) + end1.tv_nsec - start1.tv_nsec; + + uint64_t diff = diff1 + diff2; + printf("%llu\n", (long long unsigned int) diff / 1000); - printf("%f\n", elapsed); fftw_free(in); fftw_destroy_plan(p); fftw_cleanup(); diff --git a/profile.sh b/profile.sh index e3cc9c0..81f7573 100755 --- a/profile.sh +++ b/profile.sh @@ -1,7 +1,15 @@ #!/usr/bin/env bash +set -Eeuo pipefail + +if [[ "$#" -ne 1 ]] +then + echo "Usage: $0 " + exit 1 +fi + RUSTFLAGS='-Ctarget-cpu=native' cargo +nightly build --release --examples -sudo perf record --call-graph=dwarf ./target/release/examples/profile && sudo perf script -f -F +pid > processed_result.perf +sudo perf record --call-graph=dwarf ./target/release/examples/profile $1 && sudo perf script -f -F +pid > processed_result.perf echo "done! results in process_result.perf"