Changeset 7278
 Timestamp:
 Jun 30, 2009, 2:30:16 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/numpy_misc/tools/test_numpy_numeric/test_numpy_numeric.py
r7245 r7278 18 18 19 19 20 ARRAY_SIZE = 1000 * 1000 20 #ARRAY_SIZE = 1000 * 1000 21 ARRAY_SIZE = (40000, 3) 21 22 22 23 … … 75 76 This function is necessary as array(A) can cause memory overflow. 76 77 """ 77 78 # if isinstance(A, basestring):79 # msg = 'Sorry, cannot handle strings in ensure_numeric()'80 # raise Exception, msg81 78 82 79 if typecode is None: … … 150 147 151 148 149 class Array(object): 150 def __init__(self, module, f): 151 self.array = module.ones(ARRAY_SIZE, f) 152 for i in xrange(ARRAY_SIZE[0]): 153 for j in xrange(ARRAY_SIZE[1]): 154 self.array[i, j] *= float(i)+j 155 152 156 def test_usage(module, f, en, ls): 153 start_time = time.time()154 157 start_mem = mem_usage() 155 158 156 A = module.ones(ARRAY_SIZE, f) 157 B = module.ones(ARRAY_SIZE, f) 158 for i in xrange(ls): 159 A[i] *= float(i) 160 B[i] *= float(i) 159 A = Array(module, f) 160 B = Array(module, f) 161 C = Array(module, f) 162 D = module.ones(ARRAY_SIZE[1], f) 163 164 start_time = time.time() 161 165 162 166 # do some numeric calculations 163 A = en(A)164 B = en(B)165 C = module.ones(ARRAY_SIZE, f)166 C = en(C)167 167 for i in xrange(ls): 168 C = en(2.6*A + B + C + i) 168 for j in xrange(ARRAY_SIZE[0]): 169 for k in xrange(ARRAY_SIZE[1]): 170 D[0] = A.array[j, k] 171 D[1] = B.array[j, k] 172 D[2] = C.array[j, k] 169 173 170 174 stop_mem = mem_usage() … … 174 178 delta_mem = stop_mem  start_mem 175 179 176 del A, B, C 180 del A, B, C, D 177 181 gc.collect() 178 182 179 183 return (delta_time, delta_mem) 180 184 181 for loop_size in (10, 100, 1000): 182 # Do numpy work 183 (t, m) = test_usage(numpy, numpy.float, numpy_ensure_numeric, loop_size) 184 print(' numpy %4d loops: %5.1f s, %d KiB' % (loop_size, t, m)) 185 185 #for loop_size in (10, 100, 1000): 186 for loop_size in (10, 100): 186 187 # Do Numeric work 187 188 (t, m) = test_usage(Numeric, Numeric.Float, Numeric_ensure_numeric, … … 189 190 print('Numeric %4d loops: %5.1f s, %d KiB' % (loop_size, t, m)) 190 191 192 # Do numpy work 193 (t, m) = test_usage(numpy, numpy.float, numpy_ensure_numeric, loop_size) 194 print(' numpy %4d loops: %5.1f s, %d KiB' % (loop_size, t, m)) 195
Note: See TracChangeset
for help on using the changeset viewer.