Files
CS412-Applied-Algorithms/Foxsays/line_plot.py

25 lines
831 B
Python
Raw Normal View History

2025-09-13 15:36:12 -04:00
import os, sys, time, subprocess
from matplotlib import pyplot as plt
PROGRAM = "cs412_foxsays_dict.py"
SIZES_K = [50, 200, 400, 600, 800]
FILES = [f"inputs/foxsays_tleader_in_{k}k.txt" for k in SIZES_K]
sizes, runtimes = [], []
for k, f in zip(SIZES_K, FILES):
data = open(f, "rb").read()
t0 = time.perf_counter()
subprocess.run([sys.executable, PROGRAM],
input=data,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL).returncode
t1 = time.perf_counter()
sizes.append(k * 1000)
runtimes.append(t1 - t0)
plt.plot(sizes, runtimes, marker='s', lw=2)
plt.xlabel("Input Size (n)", fontsize=16)
plt.ylabel("Runtime (seconds)", fontsize=16)
plt.savefig("runtime_stats/runtime_plot.png", dpi=300, bbox_inches='tight', pad_inches=0.05)