1 | """Automatic verification that the ANUGA fitting code is not taking more time |
---|
2 | or memory than usual. This test has been tailored for computers in GA. |
---|
3 | |
---|
4 | I'm leaving a 20% error margin |
---|
5 | |
---|
6 | Note, going from version 4897 to 4917 uses more memory, based on how |
---|
7 | memory is measured here. What is actually happening is the mesh |
---|
8 | generation is using less memory, in version 4917. In version 4897 |
---|
9 | mesh gen uses and frees up more memory, so python asks for less extra |
---|
10 | memory in the fitting stage. So overall version 4917 is an |
---|
11 | improvement. |
---|
12 | |
---|
13 | RAW DATA |
---|
14 | version 4897 |
---|
15 | test_fit_time_and_mem (__main__.Test_uq) ... very start mem_usage() 98108 |
---|
16 | before fitting mem_usage() 134696 |
---|
17 | after fitting mem_usage() 155820 |
---|
18 | |
---|
19 | version 4917 |
---|
20 | test_fit_time_and_mem (__main__.Test_uq) ... very start mem_usage() 98076 |
---|
21 | before fitting mem_usage() 120012 |
---|
22 | after fitting mem_usage() 150212 |
---|
23 | time 15.19490695 |
---|
24 | mem 30200 |
---|
25 | |
---|
26 | 2009 June 22 - RW |
---|
27 | Changed the time/memory values to be exactly those found on the hardware. |
---|
28 | Took 10 measurements, used maximum in found values. |
---|
29 | |
---|
30 | """ |
---|
31 | |
---|
32 | import unittest |
---|
33 | import os, sys |
---|
34 | |
---|
35 | from anuga.fit_interpolate.benchmark_least_squares import BenchmarkLeastSquares |
---|
36 | |
---|
37 | class Test_uq(unittest.TestCase): |
---|
38 | def setUp(self): |
---|
39 | pass |
---|
40 | |
---|
41 | def tearDown(self): |
---|
42 | pass |
---|
43 | |
---|
44 | # FIXME test the time to put .pts elevation into a domain object |
---|
45 | # FIXME do tests for interpolate as well. |
---|
46 | |
---|
47 | # A version round 4872 has slower times. |
---|
48 | # That's because v4872 is using geo-ref, whereas the |
---|
49 | # previous version did not. |
---|
50 | |
---|
51 | def test_fit_time_and_mem(self): |
---|
52 | import socket |
---|
53 | |
---|
54 | # get hostname - for *nix and Windows |
---|
55 | host = socket.gethostname() |
---|
56 | |
---|
57 | # define dictionary of expected time/memory usage per machine. |
---|
58 | # key must be unique *prefix* of machine name, lowercase. |
---|
59 | # value is tuple: (time, memory) in seconds and KiB. |
---|
60 | expected_results = {'tornado': (10.8, 40468), # tornado headnode |
---|
61 | 'cyclone': (7.4, 40468), # cyclone headnode |
---|
62 | 'compute': (10.8, 40468), # cluster computenode |
---|
63 | 'nautilus': (8.1, 16104), # Ole's 32bit Ubuntu |
---|
64 | 'bogong': (14.2, 30000), # ANU? |
---|
65 | 'pc-31569': (31.6, 15000), # DSG's PC? |
---|
66 | 'pc-32572': (12.8, 15788), # Ross' 32bit work Ubuntu |
---|
67 | 'saturn': (12.8, 39404) # Ross' 64bit home Ubuntu |
---|
68 | } |
---|
69 | |
---|
70 | # run trial, report on time and memory |
---|
71 | ben = BenchmarkLeastSquares() |
---|
72 | (time, mem, num_tri, one_t, |
---|
73 | more_t, quad_t) = ben.trial(num_of_points=1000, |
---|
74 | maxArea=0.0001, |
---|
75 | is_fit=True, |
---|
76 | segments_in_mesh=False, |
---|
77 | use_file_type='pts', |
---|
78 | save=False |
---|
79 | ) |
---|
80 | |
---|
81 | # Get expected machine values, else a default set of values |
---|
82 | time_standard = 15.0 # max of above, plus a little |
---|
83 | mem_standard = 40000 |
---|
84 | for key in expected_results: |
---|
85 | if host.lower().startswith(key): |
---|
86 | (time_standard, mem_standard) = expected_results[key] |
---|
87 | break |
---|
88 | |
---|
89 | # don't want exception here, report on time *and* memory |
---|
90 | got_error = False |
---|
91 | msg = ('Time used was %.1f s, standard is %.1f s +20%% (%.1f s)' |
---|
92 | % (time, time_standard, int(time_standard*1.2))) |
---|
93 | #print msg |
---|
94 | #assert time < time_standard*1.2, msg |
---|
95 | if time > time_standard*1.2: |
---|
96 | print msg |
---|
97 | got_error = True |
---|
98 | |
---|
99 | if sys.platform == 'win32': |
---|
100 | # Memory usage does not work on windows |
---|
101 | return |
---|
102 | |
---|
103 | # Before change: https://datamining.anu.edu.au/anuga/changeset/5855 |
---|
104 | # which closed tickets 244 and 302, mem_standard was as above. |
---|
105 | # Temporary until ticket:242 is fixed increase it by 25% |
---|
106 | #mem_standard *= 1.25 |
---|
107 | # Ticket:242 is now fixed (19 Jan 2009), so mem_standard is |
---|
108 | #reduced again |
---|
109 | |
---|
110 | msg = ('Memory used was %d KiB, standard is %d KiB +20%% (%d KiB)' |
---|
111 | % (mem, mem_standard, int(mem_standard*1.2))) |
---|
112 | #print msg |
---|
113 | assert mem < mem_standard*1.2, msg |
---|
114 | |
---|
115 | if got_error: |
---|
116 | raise RuntimeError |
---|
117 | |
---|
118 | #------------------------------------------------------------- |
---|
119 | if __name__ == "__main__": |
---|
120 | suite = unittest.makeSuite(Test_uq,'test') |
---|
121 | runner = unittest.TextTestRunner(verbosity=2) |
---|
122 | runner.run(suite) |
---|