xref: /freebsd/contrib/cortex-strings/scripts/plot-align.py (revision 076ad2f836d5f49dc1375f1677335a48fe0d4b82)
1#!/usr/bin/env python
2
3"""Plot the performance of different variants of one routine versus alignment.
4"""
5
6import libplot
7
8import pylab
9
10
11def plot(records, bytes, function):
12    records = [x for x in records if x.bytes==bytes and x.function==function]
13
14    variants = libplot.unique(records, 'variant', prefer='this')
15    alignments = libplot.unique(records, ('src_alignment', 'dst_alignment'))
16
17    X = pylab.arange(len(alignments))
18    width = 1.0/(len(variants)+1)
19
20    colours = libplot.make_colours()
21
22    pylab.figure(1).set_size_inches((16, 12))
23    pylab.clf()
24
25    for i, variant in enumerate(variants):
26        heights = []
27
28        for alignment in alignments:
29            matches = [x for x in records if x.variant==variant and x.src_alignment==alignment[0] and x.dst_alignment==alignment[1]]
30
31            if matches:
32                vals = [match.bytes*match.loops/match.elapsed/(1024*1024) for
33                        match in matches]
34                mean = sum(vals)/len(vals)
35                heights.append(mean)
36            else:
37                heights.append(0)
38
39        pylab.bar(X+i*width, heights, width, color=colours.next(), label=variant)
40
41
42    axes = pylab.axes()
43    if libplot.alignments_equal(alignments):
44        alignment_labels = ["%s" % x[0] for x in alignments]
45    else:
46        alignment_labels = ["%s:%s" % (x[0], x[1]) for x in alignments]
47    axes.set_xticklabels(alignment_labels)
48    axes.set_xticks(X + 0.5)
49
50    pylab.title('Performance of different variants of %(function)s for %(bytes)d byte blocks' % locals())
51    pylab.xlabel('Alignment')
52    pylab.ylabel('Rate (MB/s)')
53    pylab.legend(loc='lower right', ncol=3)
54    pylab.grid()
55    pylab.savefig('alignment-%(function)s-%(bytes)d.png' % locals(), dpi=72)
56
57def main():
58    records = libplot.parse()
59
60    for function in libplot.unique(records, 'function'):
61        for bytes in libplot.unique(records, 'bytes'):
62            plot(records, bytes, function)
63
64    pylab.show()
65
66if __name__ == '__main__':
67    main()
68