Debian Codegraph @

bench/plot.py

raw
1 # -*- coding: utf-8 -*-
2 "This script plots the results found in bench.log."
3
4 # Copyright (C) 2010 Anders Logg
5 #
6 # This file is part of FFC.
7 #
8 # FFC is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Lesser General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # FFC is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public License
19 # along with FFC. If not, see <http://www.gnu.org/licenses/>.
20 #
21 # First added: 2010-05-13
22 # Last changed: 2010-05-13
23
24 from pylab import *
25
26 # Read logfile
27 results = {}
28 try:
29 output = open("bench.log").read()
30 except Exception:
31 output = open("results/bench.log").read()
32 for line in output.split("\n"):
33 if "," not in line: continue
34 test_case, test_option, timing = [w.strip() for w in line.split(",")]
35 try:
36 form, degree = test_case.split("_")
37 except Exception:
38 form, dim, degree = test_case.split("_")
39 form = form + "_" + dim
40 if form not in results:
41 results[form] = {}
42 if test_option not in results[form]:
43 results[form][test_option] = ([], [])
44 results[form][test_option][0].append(int(degree))
45 results[form][test_option][1].append(float(timing))
46
47 # Plot results
48 forms = sorted([form for form in results])
49 test_options = ["-r quadrature", "-r quadrature -O", "-r tensor", "-r tensor -O"]
50 bullets = ["x-", "o-", "*-", "s-"]
51 for (i, form) in enumerate(forms):
52 figure(i)
53
54 # Plot timings
55 subplot(121)
56 for (j, test_option) in enumerate(test_options):
57 q, t = results[form][test_option]
58 semilogy(q, t, bullets[j])
59 hold(True)
60 a = list(axis()); a[-1] = 50.0*a[-1]; axis(a);
61 legend(test_options, loc="upper left")
62 grid(True)
63 xlabel('degree')
64 ylabel(form)
65 title('CPU time')
66
67 # Plot speedups
68 subplot(122)
69 q0, t0 = results[form]["-r quadrature"]
70 for (j, test_option) in enumerate(test_options):
71 q, t = results[form][test_option]
72 t = [t0[k] / t[k] for k in range(len(t))]
73 semilogy(q, t, bullets[j])
74 hold(True)
75 a = list(axis()); a[-1] = 50.0*a[-1]; axis(a);
76 legend(test_options, loc="upper left")
77 grid(True)
78 xlabel('degree')
79 title("Speedup vs '-r quadrature'")
80
81 show()