for INF-2B Coursework 1
To help determine the x-over point.
python3 vis.py matcherTimes.txtBora M. Alper [email protected]
for INF-2B Coursework 1
To help determine the x-over point.
python3 vis.py matcherTimes.txtBora M. Alper [email protected]
| #!/usr/bin/env python3 | |
| # Written by Bora M. Alper <[email protected]> | |
| import collections | |
| import re | |
| import sys | |
| import matplotlib as mpl | |
| import matplotlib.pyplot as plt | |
| Entry = collections.namedtuple("Entry", ["text_size", "pat_size", "naive_rt", "kmp_rt"]) | |
| entries = [] # type: List[Entry] | |
| with open("matcherTimes.txt" if len(sys.argv) == 1 else sys.argv[1]) as f: | |
| for i, line in enumerate(f): | |
| if i <= 1: # skip headers | |
| continue | |
| m = re.match(r"^ *(\d*)\t *(\d*)\t *(\d*)\t *(\d*)$", line) | |
| entries.append(Entry(int(m.group(2)), int(m.group(1)), int(m.group(3)), int(m.group(4)))) | |
| plt.figure("Comparison of Runtimes by Pattern Size") | |
| for row, p in enumerate([10, 100, 1000, 10000, 100000], 1): | |
| x = list(filter(lambda x: x.pat_size == p, entries)) | |
| ax = plt.subplot(5, 1, row) | |
| ax.set_title("m = %d" % (p,)) | |
| ax.plot([e.text_size for e in x], [e.naive_rt for e in x], "r--", label="Naive") | |
| ax.plot([e.text_size for e in x], [e.kmp_rt for e in x], "b--", label="KMP") | |
| ax.get_xaxis().set_major_formatter( | |
| mpl.ticker.FuncFormatter(lambda x, p: format(int(x), ',')) | |
| ) | |
| plt.ylabel("Runtime") | |
| ax.grid(True) | |
| ax.legend() | |
| plt.subplots_adjust(top=0.97, bottom=0.03, left=0.05, right=0.99, hspace=0.34) | |
| print("x axis of each subplot is m (text size)") | |
| plt.show() |