comparison scripts/testfun/speed.m @ 8506:bc982528de11

comment style fixes
author John W. Eaton <jwe@octave.org>
date Tue, 13 Jan 2009 11:56:00 -0500
parents cf59d542f33e
children cadc73247d65
comparison
equal deleted inserted replaced
8505:124dd27bedae 8506:bc982528de11
167 __tol = eps; 167 __tol = eps;
168 endif 168 endif
169 169
170 __numtests = 15; 170 __numtests = 15;
171 171
172 ## Let user specify range of n 172 ## Let user specify range of n.
173 if (isscalar (__max_n)) 173 if (isscalar (__max_n))
174 __min_n = 1; 174 __min_n = 1;
175 assert (__max_n > __min_n); 175 assert (__max_n > __min_n);
176 __test_n = logspace (0, log10 (__max_n), __numtests); 176 __test_n = logspace (0, log10 (__max_n), __numtests);
177 elseif (length (__max_n) == 2) 177 elseif (length (__max_n) == 2)
180 assert (__min_n >= 1); 180 assert (__min_n >= 1);
181 __test_n = logspace (log10 (__min_n), log10 (__max_n), __numtests); 181 __test_n = logspace (log10 (__min_n), log10 (__max_n), __numtests);
182 else 182 else
183 __test_n = __max_n; 183 __test_n = __max_n;
184 endif 184 endif
185 __test_n = unique (round (__test_n)); # Force n to be an integer 185 ## Force n to be an integer.
186 __test_n = unique (round (__test_n));
186 assert (__test_n >= 1); 187 assert (__test_n >= 1);
187 188
188 __torig = __tnew = zeros (size (__test_n)); 189 __torig = __tnew = zeros (size (__test_n));
189 190
190 disp (cstrcat ("testing ", __f1, "\ninit: ", __init)); 191 disp (cstrcat ("testing ", __f1, "\ninit: ", __init));
191 192
192 ## make sure the functions are freshly loaded by evaluating them at 193 ## Make sure the functions are freshly loaded by evaluating them at
193 ## test_n(1); first have to initialize the args though. 194 ## test_n(1); first have to initialize the args though.
194 n = 1; 195 n = 1;
195 k = 0; 196 k = 0;
196 eval (cstrcat (__init, ";")); 197 eval (cstrcat (__init, ";"));
197 if (! isempty (__f2)) 198 if (! isempty (__f2))
198 eval (cstrcat (__f2, ";")); 199 eval (cstrcat (__f2, ";"));
199 endif 200 endif
200 eval (cstrcat (__f1, ";")); 201 eval (cstrcat (__f1, ";"));
201 202
202 ## run the tests 203 ## Run the tests.
203 for k = 1:length (__test_n) 204 for k = 1:length (__test_n)
204 n = __test_n(k); 205 n = __test_n(k);
205 eval (cstrcat (__init, ";")); 206 eval (cstrcat (__init, ";"));
206 207
207 printf ("n%i=%i ",k, n); 208 printf ("n%i=%i ",k, n);
225 assert (__v1, __v2, __tol); 226 assert (__v1, __v2, __tol);
226 endif 227 endif
227 endif 228 endif
228 endfor 229 endfor
229 230
230 ## Drop times of zero 231 ## Drop times of zero.
231 if (! isempty (__f2)) 232 if (! isempty (__f2))
232 zidx = (__tnew < 100*eps | __torig < 100*eps); 233 zidx = (__tnew < 100*eps | __torig < 100*eps);
233 __test_n(zidx) = []; 234 __test_n(zidx) = [];
234 __tnew(zidx) = []; 235 __tnew(zidx) = [];
235 __torig(zidx) = []; 236 __torig(zidx) = [];
237 zidx = (__tnew < 100*eps); 238 zidx = (__tnew < 100*eps);
238 __test_n(zidx) = []; 239 __test_n(zidx) = [];
239 __tnew(zidx) = []; 240 __tnew(zidx) = [];
240 endif 241 endif
241 242
242 ## Approximate time complexity and return it if requested 243 ## Approximate time complexity and return it if requested.
243 tailidx = ceil(length(__test_n)/2):length(__test_n); 244 tailidx = ceil(length(__test_n)/2):length(__test_n);
244 p = polyfit (log (__test_n(tailidx)), log (__tnew(tailidx)), 1); 245 p = polyfit (log (__test_n(tailidx)), log (__tnew(tailidx)), 1);
245 if (nargout > 0) 246 if (nargout > 0)
246 __order.p = p(1); 247 __order.p = p(1);
247 __order.a = exp (p(2)); 248 __order.a = exp (p(2));
295 order = sprintf ("O(n^%g)", round (10*p(1))/10); 296 order = sprintf ("O(n^%g)", round (10*p(1))/10);
296 v = polyval (p, log (__test_n(tailidx))); 297 v = polyval (p, log (__test_n(tailidx)));
297 298
298 loglog (__test_n(tailidx), exp(v)*1000, sprintf ("b;%s;", order)); 299 loglog (__test_n(tailidx), exp(v)*1000, sprintf ("b;%s;", order));
299 300
300 ## Get base time to 1 digit of accuracy 301 ## Get base time to 1 digit of accuracy.
301 dt = exp (p(2)); 302 dt = exp (p(2));
302 dt = floor (dt/10^floor(log10(dt)))*10^floor(log10(dt)); 303 dt = floor (dt/10^floor(log10(dt)))*10^floor(log10(dt));
303 if (log10 (dt) >= -0.5) 304 if (log10 (dt) >= -0.5)
304 time = sprintf ("%g s", dt); 305 time = sprintf ("%g s", dt);
305 elseif (log10 (dt) >= -3.5) 306 elseif (log10 (dt) >= -3.5)