SyFi
0.3
|
00001 #!/usr/bin/env python 00002 00003 __authors__ = "Martin Sandve Alnes" 00004 __date__ = "2012-05-16" 00005 00006 from test_tempdir_base import TempDirTestBase 00007 import swiginac 00008 import SyFi 00009 import sfc 00010 from ufl import * 00011 from time import time 00012 00013 def info(*args): 00014 if 0: print " ".join(map(str,args)) 00015 00016 class TestCache(TempDirTestBase): 00017 def __init__(self, *args, **kwargs): 00018 TempDirTestBase.__init__(self, *args, **kwargs) 00019 00020 def setUp(self): 00021 TempDirTestBase.setUp(self) 00022 self.options.code.integral.integration_method = "quadrature" 00023 00024 def tearDown(self): 00025 TempDirTestBase.tearDown(self) 00026 00027 def test_cache(self): 00028 cells = (interval, triangle, tetrahedron) #, quadrilateral, hexahedron) 00029 times = [] 00030 for take in range(3): 00031 info("="*40, "Take", take) 00032 avg, n = 0.0, 0 00033 for cell in cells: 00034 for degree in range(1, 3): 00035 U1 = FiniteElement("CG", cell, degree) 00036 U2 = FiniteElement("CG", cell, degree+1) 00037 V1 = TensorElement("CG", cell, degree) 00038 V2 = VectorElement("CG", cell, degree+1) 00039 V3 = FiniteElement("CG", cell, degree+2) 00040 00041 inputs = [U1, [U1], 00042 U1 * U2, 00043 V1 * V2 * V3] 00044 00045 for input in inputs: 00046 t1 = time() 00047 sfc.jit(input) # FIXME: Use local cache, clear before test 00048 t2 = time() 00049 t = t2 - t1 00050 info("Time for %s: %.4f s" % (repr(input), t)) 00051 avg += t 00052 n += 1 00053 avg /= n 00054 info("Average for take", take, "is", avg) 00055 times.append(avg) 00056 #self.assertLess(times[-1], times[0])