Skip to content

Commit

Permalink
Update benchmark, plotting, and profiling scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Feb 28, 2024
1 parent b322fc2 commit 4c3b8f4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
18 changes: 17 additions & 1 deletion benches/benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ end=$2
max_iters=1000 # Set your desired maximum number of iterations

OUTPUT_DIR=benchmark-data.$(date +"%Y.%m.%d.%H-%M-%S")
mkdir -p "$OUTPUT_DIR"/fftw3 && mkdir "$OUTPUT_DIR"/rustfft && mkdir "$OUTPUT_DIR"/phastft
mkdir -p "$OUTPUT_DIR"/fftw3 && mkdir "$OUTPUT_DIR"/rustfft && mkdir "$OUTPUT_DIR"/phastft && mkdir "$OUTPUT_DIR"/fftwrb

RUSTFLAGS="-C target-cpu=native"

benchmark_fftw3() {
make clean && make
Expand Down Expand Up @@ -58,6 +59,21 @@ benchmark_rustfft() {
done
}

benchmark_rs_fftw3() {
cargo clean && cargo build --release --examples

for n in $(seq "$start" "$end"); do
iters=$((2**($end - $n)))
iters=$((iters > max_iters ? max_iters : iters))
echo "Running FFTW3 Rust bindings benchmark for N = 2^${n}..."

for _ in $(seq 1 "$iters"); do
../target/release/examples/fftwrb "${n}" >> "${OUTPUT_DIR}"/fftwrb/size_"${n}"
done
done
}

benchmark_rs_fftw3
benchmark_fftw3
benchmark_phastft
benchmark_rustfft
14 changes: 9 additions & 5 deletions benches/benchmark_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,27 @@ def plot(data: dict[str, list], n_range: range) -> None:
y0 = np.asarray(data["fftw3"])
y1 = np.asarray(data["phastft"])
y2 = np.asarray(data["rustfft"])
y3 = np.asarray(data["fftwrb"])

y0 /= y2
y1 /= y2
y3 /= y2

df = pd.DataFrame(
{
"RustFFT": np.ones(len(index)),
"FFTW3": y0,
"PhastFT": y1,
"FFTW3-RB": y3,
},
index=index,
)

title = "PhastFT vs. FFTW3 vs. RustFFT"
df.plot(kind="bar", linewidth=2, rot=0, title=title)
df.plot(kind="bar", linewidth=2, rot=0)
plt.title("PhastFT vs. FFTW3 vs. FFTW3 RB vs. RustFFT", fontsize=14)
plt.xticks(fontsize=8, rotation=-45)
plt.xlabel("size of input")
plt.ylabel("Execution Time Ratio\n(relative to RustFFT)")
plt.xlabel("size of input", fontsize=10)
plt.ylabel("Execution Time Ratio\n(relative to RustFFT)", fontsize=11)
plt.legend(loc="best")
plt.tight_layout()
plt.savefig(f"benchmarks_bar_plot_{n_range.start}_{n_range.stop -1}.png", dpi=600)
Expand All @@ -71,7 +74,7 @@ def plot(data: dict[str, list], n_range: range) -> None:

def main():
"""Entry point... yay"""
lib_names = ("rustfft", "phastft", "fftw3")
lib_names = ("rustfft", "phastft", "fftw3", "fftwrb")
ranges = (range(4, 13), range(13, 30))

for n_range in ranges:
Expand All @@ -89,6 +92,7 @@ def main():
len(all_data["rustfft"])
== len(all_data["fftw3"])
== len(all_data["phastft"])
== len(all_data["fftwrb"])
)
plot(all_data, n_range)

Expand Down
4 changes: 2 additions & 2 deletions profile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ then
exit 1
fi

RUSTFLAGS='-Ctarget-cpu=native' cargo +nightly build --release --examples
RUSTFLAGS='-Ctarget-cpu=native' cargo +nightly build --profile profiling --example profile

sudo perf record --call-graph=dwarf ./target/release/examples/profile $1 && sudo perf script -f -F +pid > processed_result.perf
sudo perf record --call-graph=dwarf ./target/profiling/examples/profile $1 && sudo perf script -f -F +pid > processed_result.perf

echo "done! results in process_result.perf"

0 comments on commit 4c3b8f4

Please sign in to comment.