kmod/scripts/plot-timing

53 lines
1.2 KiB
Python
Executable File

#!/usr/bin/python
import argparse
import os.path
import sys
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid.anchored_artists import AnchoredText
def parse_table(f):
x = []
y = []
for line in f:
if len(line) < 2 or not line[0].isdigit():
continue
val = line.split()[0:2]
x += [int(val[0])]
y += [float(val[1])]
return x, y
parser = argparse.ArgumentParser()
parser.add_argument('--name', type=str, default='')
parser.add_argument('--save', action='store_true')
parser.add_argument('file', nargs='*')
args = parser.parse_args()
fig = plt.figure()
ax = fig.add_subplot(111, axisbg='#f6f6f6')
for fn in args.file:
with open(fn) as f:
x, y = parse_table(f)
ax.plot(x, y, label=os.path.splitext(os.path.basename(fn))[0])
ax.set_xlabel('length')
ax.set_ylabel('clock cycles')
ax.axis('tight')
leg = ax.legend(loc=2, fancybox=True, shadow=True)
leg.get_frame().set_alpha(0.5)
fig.suptitle('Hash function timings: %s' % args.name, weight='bold',
size='large')
fig.tight_layout()
plt.subplots_adjust(top=0.9)
if args.save:
fig.savefig(os.path.dirname(args.file[0]) + '/plot.png')
else:
plt.show()