Skip to content

Commit

Permalink
Automate findings of latest benchmark results
Browse files Browse the repository at this point in the history
  • Loading branch information
smu160 committed Feb 8, 2024
1 parent 2772731 commit b9dfbce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
Empty file modified benches/benchmark.sh
100644 → 100755
Empty file.
9 changes: 6 additions & 3 deletions benches/benchmark_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pandas as pd

from utils import bytes2human
from utils import bytes2human, find_directory

plt.style.use("fivethirtyeight")

Expand Down Expand Up @@ -73,11 +73,14 @@ def plot(data: dict[str, list], n_range: range) -> None:
def main():
lib_names = ("rustfft", "phastft", "fftw3")
n_range = range(12, 30)

all_data = {}

for lib in lib_names:
data = build_and_clean_data("benchmark-data.2024.02.02.19-10-51", n_range, lib)
root_folder = find_directory()
if root_folder is None:
raise FileNotFoundError("unable to find the benchmark data directory")

data = build_and_clean_data(root_folder, n_range, lib)
all_data[lib] = data

assert (
Expand Down
9 changes: 7 additions & 2 deletions benches/py_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ def main() -> None:


def read_csv_to_dict(file_path: str) -> dict:
data = {"n": [], "phastft_time": [], "numpy_fft_time": [], "pyfftw_fft_time": []}
data: dict[str, list] = {
"n": [],
"phastft_time": [],
"numpy_fft_time": [],
"pyfftw_fft_time": [],
}
with open(file_path, newline="") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
Expand All @@ -113,7 +118,7 @@ def plot_elapsed_times(data: dict) -> None:
phastft_timings = np.asarray(data["phastft_time"])

plt.plot(index, np_fft_timings, label="NumPy FFT", lw=0.8)
plt.plot(index, pyfftw_timings, label="PyFFTW FFT", lw=0.8)
plt.plot(index, pyfftw_timings, label="PyFFTW FFT", lw=0.8)
plt.plot(index, phastft_timings, label="PhastFT", lw=0.98)

plt.title("FFT Elapsed Times Comparison")
Expand Down
33 changes: 33 additions & 0 deletions benches/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Utility functions for plotting that are common to all scripts
"""

import os
import re
from datetime import datetime


SYMBOLS = {
"customary": ("B", "K", "M", "G", "T", "P", "E", "Z", "Y"),
"customary_ext": (
Expand Down Expand Up @@ -42,3 +47,31 @@ def bytes2human(n, format="%(value).0f %(symbol)s", symbols="customary"):
return format % dict(symbol=symbols[0], value=n)


def find_directory(pattern="benchmark-data"):
current_dir = os.getcwd()

# List all directories in the current directory
all_dirs = [
d
for d in os.listdir(current_dir)
if os.path.isdir(os.path.join(current_dir, d))
]

# Define the regex pattern for matching
date_pattern = re.compile(r"\d{4}\.\d{2}\.\d{2}\.\d{2}-\d{2}-\d{2}")

# Iterate through directories and check if they match the pattern
matching_dirs = [d for d in all_dirs if pattern in d and date_pattern.search(d)]

if matching_dirs:
# Sort directories based on the date in the directory name
matching_dirs.sort(
key=lambda x: datetime.strptime(
date_pattern.search(x).group(), "%Y.%m.%d.%H-%M-%S"
)
)
return os.path.join(
current_dir, matching_dirs[-1]
) # Return the latest matching directory
else:
return None # No matching directory found

0 comments on commit b9dfbce

Please sign in to comment.