#! /usr/bin/python3
import sys
import matplotlib.pyplot as plt
from math import *

if len(sys.argv) != 3:
    print("usage:", sys.argv[0], " <filename1> <filename2>")
    exit()


def read_plot_from_file(filename):
    # open file and remove newlines. readlines is okay b/c
    # the input file shouldn't be thaaaat big
    f=open(filename)
    lines = [line.strip() for line in f.readlines()]
    f.close()

    # third line has the title of each implementation
    names=[name for name in lines[2].split(" ")]

    # first column defines the inputs
    inputs = [float(x.split(" ")[0]) for x in lines[3:]]

    # plot inputs against output column
    data = {}
    for i in range(len(names)):
        data[names[i]] = [float(x.split(" ")[i+1].rstrip("s")) for x in lines[3:]]

    return (inputs,data)


(inputs1,data1) = read_plot_from_file(sys.argv[1])
(inputs2,data2) = read_plot_from_file(sys.argv[2])

plt.figure(figsize=(9, 5), dpi=80)
plt.xlabel("Error")
plt.ylabel("Speedup from padding coefficients to cache line")
for k in data1:
    plt.semilogx(inputs1, [x1/x2 for x1,x2 in zip(data1[k],data2[k])], '-', label=k)

plt.grid(True)
plt.legend(loc="best",fancybox=True, shadow=True, fontsize='small')
plt.subplots_adjust(left=0.07,right=0.992,top=0.99,bottom=0.11,wspace=0.08)
plt.savefig('padding_ratios.eps', format='eps')
plt.show()
