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