Skip to content

Instantly share code, notes, and snippets.

@aidenfoxivey
Last active October 19, 2023 21:14
Show Gist options
  • Save aidenfoxivey/08bd19b1e5058dac25607e37565dbaaa to your computer and use it in GitHub Desktop.
Save aidenfoxivey/08bd19b1e5058dac25607e37565dbaaa to your computer and use it in GitHub Desktop.
ECE252 Lab 3 Run Script
#!/usr/bin/env python3
import subprocess
import time
import csv
import socket
import re
def main():
timestamp = str(round(time.time()))
hname = socket.gethostname()
csv_path = f"results/lab3_{hname}_{timestamp}.csv"
with open(csv_path, "w", newline="") as csvfile:
writer = csv.writer(csvfile, dialect="excel")
writer.writerow(["B", "P", "C", "X", "N", "Time"])
for test_case in cases:
(b, p, c, x, n) = tuple(str(x) for x in test_case)
print(["./paster2", b, p, c, x, n])
# Note that for each given (B, P, C, X, N ) value in the table, you
# need to run the pro- gram n times and compute the average time.
# We recommend n = 5.
acc = 0.0
for i in range(0, 5):
sub = subprocess.run(["./paster2", b, p, c, x, n])
number = float(re.findall(r"[-+]?\d*\.\d+|\d+", sub.stdout))
acc += number
time_taken = acc / 5.0
writer.writerow([b, p, c, x, n, time_taken])
cases = [(5, 1, 1, 0, 1),
(5, 1, 5, 0, 1),
(5, 5, 1, 0, 1),
(5, 5, 5, 0, 1),
(10, 1, 1, 0, 1),
(10, 1, 5, 0, 1),
(10, 1, 10, 0, 1),
(10, 5, 1, 0, 1),
(10, 5, 5, 0, 1),
(10, 5, 10, 0, 1),
(10, 10, 1, 0, 1),
(10, 10, 5, 0, 1),
(10, 10, 10, 0, 1),
(5, 1, 1, 200, 1),
(5, 1, 5, 200, 1),
(5, 5, 1, 200, 1),
(5, 5, 5, 200, 1),
(10, 1, 1, 200, 1),
(10, 1, 5, 200, 1),
(10, 1, 10, 200, 1),
(10, 5, 1, 200, 1),
(10, 5, 5, 200, 1),
(10, 5, 10, 200, 1),
(10, 10, 1, 200, 1),
(10, 10, 5, 200, 1),
(10, 10, 10, 200, 1),
(5, 1, 1, 400, 1),
(5, 1, 5, 400, 1),
(5, 5, 1, 400, 1),
(5, 5, 5, 400, 1),
(10, 1, 1, 400, 1),
(10, 1, 5, 400, 1),
(10, 1, 10, 400, 1),
(10, 5, 1, 400, 1),
(10, 5, 5, 400, 1),
(10, 5, 10, 400, 1),
(10, 10, 1, 400, 1),
(10, 10, 5, 400, 1),
(10, 10, 10, 400, 1)]
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment