Skip to content

Commit

Permalink
Merge branch 'main' of github.com:QuState/PhastFT
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Feb 9, 2024
2 parents 901bff7 + d95035e commit 221db1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
27 changes: 21 additions & 6 deletions benches/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,46 @@
#include <math.h>
#include <fftw3.h>
#include <time.h>
#include <stdint.h> // uint64
#include <time.h> // clock_gettime

#define BILLION 1000000000L


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;

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++) {
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);
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();
Expand Down
10 changes: 9 additions & 1 deletion profile.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/usr/bin/env bash

set -Eeuo pipefail

if [[ "$#" -ne 1 ]]
then
echo "Usage: $0 <n>"
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"

0 comments on commit 221db1d

Please sign in to comment.