39 lines
1.5 KiB
Python
Executable File
39 lines
1.5 KiB
Python
Executable File
"""Benchmark waktu pemrosesan pada jumlah data berbeda (metrik 'Waktu Pemrosesan', Bab 4.6 & 5.3).
|
|
python scripts/benchmark.py --fractions 0.1 0.25 0.5 1.0
|
|
Hasil: <storage lokal>/reports/benchmark.csv"""
|
|
import argparse
|
|
import csv
|
|
import json
|
|
import subprocess
|
|
import sys
|
|
|
|
import config
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--fractions", type=float, nargs="+", default=[0.1, 0.25, 0.5, 1.0])
|
|
args = ap.parse_args()
|
|
rows = []
|
|
for f in args.fractions:
|
|
suffix = f"_bench{int(f * 100)}"
|
|
subprocess.run([sys.executable, "-m", "spark_jobs.clean_job", "--sample-fraction", str(f), "--out-suffix", suffix], check=True)
|
|
subprocess.run([sys.executable, "-m", "spark_jobs.analysis_job", "--out-suffix", suffix], check=True)
|
|
clean = json.loads((config.REPORT_DIR / f"clean_stats{suffix}.json").read_text())
|
|
ana = json.loads((config.REPORT_DIR / f"analysis_stats{suffix}.json").read_text())
|
|
rows.append({"fraksi_data": f, "n_raw": clean["n_raw"], "n_final": clean["n_final"],
|
|
"detik_cleaning": clean["seconds"], "detik_analisis": ana["seconds"],
|
|
"detik_total": round(clean["seconds"] + ana["seconds"], 2)})
|
|
out = config.REPORT_DIR / "benchmark.csv"
|
|
with open(out, "w", newline="", encoding="utf-8") as fh:
|
|
w = csv.DictWriter(fh, fieldnames=rows[0].keys())
|
|
w.writeheader()
|
|
w.writerows(rows)
|
|
print(f"benchmark disimpan: {out}")
|
|
for r in rows:
|
|
print(r)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|