yum/vfft

git clone https://git.yummers.dev/yum/vfft

yumAdd script to export criterion results to csvfbfe6b0

master
2.1 KiB64 linesraw
1#!/usr/bin/env -S uv run --script
2#
3# /// script
4# requires-python = ">=3.12"
5# dependencies = []
6# ///
7
8# Exports latest Criterion results to a .csv file.
9
10import argparse
11import csv
12from datetime import date
13import json
14import subprocess
15from pathlib import Path
16
17def parse_args():
18    parser = argparse.ArgumentParser(description="Convert latest Criterion results to CSV.")
19    parser.add_argument("suffix", help="CSV filename suffix, e.g. 9800x3d")
20    args = parser.parse_args()
21    return args
22
23def filename(args):
24    cmd = ["git", "rev-parse", "--short=16", "HEAD"]
25    commit = subprocess.check_output(cmd, text=True).strip()
26    return f"{commit}_{args.suffix}.csv"
27
28def get_save_path(args):
29    measurements = Path(__file__).resolve().parent
30    return measurements / filename(args)
31
32def parse_data(args):
33    script_dir = Path(__file__).resolve()
34    project_root = script_dir.parents[1]
35    criterion = project_root / "target/criterion"
36    files = list(criterion.glob("size *, fft v8/new/estimates.json"))
37    latest_date = max(date.fromtimestamp(path.stat().st_mtime) for path in files)
38    data = []
39    for path in files:
40        # Ignore sizes left over from runs on earlier dates.
41        if date.fromtimestamp(path.stat().st_mtime) != latest_date:
42            continue
43        size = int(path.parent.parent.name.split(",")[0].split()[1])
44        row = [size]
45        for implementation in ["reference", "fft v8"]:
46            estimates_path = criterion / f"size {size}, {implementation}/new/estimates.json"
47            assert date.fromtimestamp(estimates_path.stat().st_mtime) == latest_date
48            estimates = json.loads(estimates_path.read_text())
49            row.append(estimates["slope"]["point_estimate"])
50        data.append(row)
51    return sorted(data)
52
53def main():
54    args = parse_args()
55    data = parse_data(args)
56    with open(get_save_path(args), "w", newline="", encoding="utf-8") as file:
57        writer = csv.writer(file, lineterminator="\n")
58        writer.writerow(["Input length", "rustfft", "vfft (fft v8)"])
59        writer.writerows(data)
60    print(filename(args))
61
62if __name__ == "__main__":
63    main()
64