1 |
""" |
2 |
Miscellaneous escript/Data timing tests. |
3 |
|
4 |
Version $Id$ |
5 |
""" |
6 |
|
7 |
import sys |
8 |
import os |
9 |
import time |
10 |
|
11 |
from esys.escript import * |
12 |
from esys import bruce |
13 |
|
14 |
# |
15 |
# ================== data values to test with ========================= |
16 |
|
17 |
arglist = [ \ |
18 |
3.0, \ |
19 |
[3.0,4.0], \ |
20 |
[[1.0,2.0],[3.0,4.0]], \ |
21 |
[[[15.0,8.0],[12.0,8.0]],[[-9.0,9.0],[13.0,8.0]]], \ |
22 |
[[[[14.0,7.0],[11.0,8.5]],[[-970,9.2],[18.0,8.0]]],[[[-4.4,7.0],[93.0,8.0]],[[-1.0,9.4],[12.0,9.0]]]] \ |
23 |
] |
24 |
|
25 |
testlist = [ |
26 |
"_trace ", |
27 |
"_maxval ", |
28 |
"_minval ", |
29 |
"_wherePositive ", |
30 |
"_whereNegative ", |
31 |
"_whereNonNegative", |
32 |
"_whereNonPositive", |
33 |
"_whereZero ", |
34 |
"_whereNonZero ", |
35 |
"_sin ", |
36 |
"_cos ", |
37 |
"_tan ", |
38 |
"_asin ", |
39 |
"_acos ", |
40 |
"_atan ", |
41 |
"_sinh ", |
42 |
"_cosh ", |
43 |
"_tanh ", |
44 |
"_asinh ", |
45 |
"_acosh ", |
46 |
"_atanh ", |
47 |
"_exp ", |
48 |
"_sqrt ", |
49 |
"_log10 ", |
50 |
"_log ", |
51 |
"_sign ", |
52 |
"_Lsup ", |
53 |
"_sup ", |
54 |
"_inf " |
55 |
] |
56 |
|
57 |
# |
58 |
# ================== method definitions ========================= |
59 |
|
60 |
def prepareArg(val,ex,wh): |
61 |
if ex=="Expanded": |
62 |
exx=True |
63 |
else: |
64 |
exx=False |
65 |
out=Data(val,what=wh,expand=exx) |
66 |
if ex=="Tagged": |
67 |
out.tag() |
68 |
return out |
69 |
|
70 |
def getStartTime(): |
71 |
return time.clock() |
72 |
|
73 |
def calcElapsedTime(starttime): |
74 |
stoptime = time.clock() |
75 |
elapsed = stoptime - starttime |
76 |
print "\t\t", elapsed |
77 |
|
78 |
def runTest(arg,test): |
79 |
print "\t\t", test, |
80 |
test_name = test.rstrip() |
81 |
result = arg.__getattribute__(test_name)() |
82 |
del result |
83 |
|
84 |
# |
85 |
# ===================== main ============================== |
86 |
|
87 |
msh=bruce.Rectangle(1000,1000) |
88 |
|
89 |
for wh in [Function(msh),ContinuousFunction(msh)]: |
90 |
|
91 |
print "\n", wh, ":" |
92 |
|
93 |
for ex in ["Constant", "Tagged", "Expanded"]: |
94 |
|
95 |
for a in arglist: |
96 |
|
97 |
arg=prepareArg(a,ex,wh) |
98 |
|
99 |
print "\n\t", ex, "Rank", arg.getRank(), "==>" |
100 |
print "\n\t\tFunction\t\tElapsed time" |
101 |
print "\t\t--------\t\t------------" |
102 |
|
103 |
for test in testlist: |
104 |
|
105 |
starttime = getStartTime() |
106 |
|
107 |
runTest(arg,test) |
108 |
|
109 |
calcElapsedTime(starttime) |
110 |
|
111 |
sys.exit(0) |
112 |
# end |