File: bench.py

package info (click to toggle)
ffc 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 31,928 kB
  • ctags: 5,610
  • sloc: cpp: 200,834; python: 14,417; perl: 351; makefile: 21; sh: 6
file content (45 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""This script runs a benchmark study on the form files found in the
current directory. It relies on the regression test script for
timings."""

__author__ = "Anders Logg"
__date__ = "2010-05-11"
__copyright__ = "Copyright (C) 2010 " + __author__
__license__  = "GNU GPL version 3 or any later version"

import os, glob
from utils import print_table

# Test options
test_options = ["-r tensor", "-r tensor -O", "-r quadrature", "-r quadrature -O"]

# Get list of test cases
test_cases = sorted([f.split(".")[0] for f in glob.glob("*.ufl")])

# Open logfile
logfile = open("bench.log", "w")

# Iterate over options
os.chdir("../test/regression")
table = {}
for (j, test_option) in enumerate(test_options):

    # Run benchmark
    print "\nUsing options %s\n" % test_option
    os.system("python test.py --bench %s" % test_option)

    # Collect results
    for (i, test_case) in enumerate(test_cases):
        output = open("output/%s.out" % test_case).read()
        lines = [line for line in output.split("\n") if "bench" in line]
        if not len(lines) == 1:
            raise RuntimeError, "Unable to extract benchmark data for test case %s" % test_case
        timing = float(lines[0].split(":")[-1])
        table[(i, j)] = (test_case, test_option, timing)
        logfile.write("%s, %s, %g\n" % (test_case, test_option, timing))

# Close logfile
logfile.close()

# Print results
print_table(table, "FFC bench")