| 1 |
# -*- coding: utf-8 -*- |
| 2 |
"""This script runs a benchmark study on the form files found in the |
| 3 |
current directory. It relies on the regression test script for |
| 4 |
timings.""" |
| 5 |
|
| 6 |
# Copyright (C) 2010 Anders Logg |
| 7 |
# |
| 8 |
# This file is part of FFC. |
| 9 |
# |
| 10 |
# FFC is free software: you can redistribute it and/or modify |
| 11 |
# it under the terms of the GNU Lesser General Public License as published by |
| 12 |
# the Free Software Foundation, either version 3 of the License, or |
| 13 |
# (at your option) any later version. |
| 14 |
# |
| 15 |
# FFC is distributed in the hope that it will be useful, |
| 16 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
# GNU Lesser General Public License for more details. |
| 19 |
# |
| 20 |
# You should have received a copy of the GNU Lesser General Public License |
| 21 |
# along with FFC. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
import os |
| 24 |
import glob |
| 25 |
import sys |
| 26 |
from utils import print_table |
| 27 |
|
| 28 |
# Test options |
| 29 |
test_options = ["-r tensor", |
| 30 |
#"-r tensor -O", |
| 31 |
"-r quadrature", |
| 32 |
"-r quadrature -O", |
| 33 |
"-r uflacs"] |
| 34 |
|
| 35 |
# Get list of test cases |
| 36 |
test_cases = sorted([f.split(".")[0] for f in glob.glob("*.ufl")]) |
| 37 |
|
| 38 |
# Open logfile |
| 39 |
logfile = open("bench.log", "w") |
| 40 |
|
| 41 |
# Iterate over options |
| 42 |
os.chdir("../test/regression") |
| 43 |
table = {} |
| 44 |
for (j, test_option) in enumerate(test_options): |
| 45 |
|
| 46 |
# Run benchmark |
| 47 |
print("\nUsing options %s\n" % test_option) |
| 48 |
os.system(sys.executable + " test.py --bench %s" % test_option) |
| 49 |
|
| 50 |
# Collect results |
| 51 |
for (i, test_case) in enumerate(test_cases): |
| 52 |
output = open("output/%s.out" % test_case).read() |
| 53 |
lines = [line for line in output.split("\n") if "bench" in line] |
| 54 |
if not len(lines) == 1: |
| 55 |
raise RuntimeError("Unable to extract benchmark data for test case %s" % test_case) |
| 56 |
timing = float(lines[0].split(":")[-1]) |
| 57 |
table[(i, j)] = (test_case, test_option, timing) |
| 58 |
logfile.write("%s, %s, %g\n" % (test_case, test_option, timing)) |
| 59 |
|
| 60 |
# Close logfile |
| 61 |
logfile.close() |
| 62 |
|
| 63 |
# Print results |
| 64 |
print_table(table, "FFC bench") |