comparison scripts/testfun/speed.m @ 7540:3422f39573b1

strcat.m: Matlab compatibility, with cstrcat.m replacing conventional strcat.m.
author Ben Abbott <bpabbott@mac.com>
date Thu, 28 Feb 2008 02:41:19 -0500
parents a1dbe9d80eee
children cf59d542f33e
comparison
equal deleted inserted replaced
7539:3e107d73aeb4 7540:3422f39573b1
185 __test_n = unique (round (__test_n)); # Force n to be an integer 185 __test_n = unique (round (__test_n)); # Force n to be an integer
186 assert (__test_n >= 1); 186 assert (__test_n >= 1);
187 187
188 __torig = __tnew = zeros (size (__test_n)); 188 __torig = __tnew = zeros (size (__test_n));
189 189
190 disp (strcat ("testing ", __f1, "\ninit: ", __init)); 190 disp (cstrcat ("testing ", __f1, "\ninit: ", __init));
191 191
192 ## make sure the functions are freshly loaded by evaluating them at 192 ## make sure the functions are freshly loaded by evaluating them at
193 ## test_n(1); first have to initialize the args though. 193 ## test_n(1); first have to initialize the args though.
194 n = 1; 194 n = 1;
195 k = 0; 195 k = 0;
196 eval (strcat (__init, ";")); 196 eval (cstrcat (__init, ";"));
197 if (! isempty (__f2)) 197 if (! isempty (__f2))
198 eval (strcat (__f2, ";")); 198 eval (cstrcat (__f2, ";"));
199 endif 199 endif
200 eval (strcat (__f1, ";")); 200 eval (cstrcat (__f1, ";"));
201 201
202 ## run the tests 202 ## run the tests
203 for k = 1:length (__test_n) 203 for k = 1:length (__test_n)
204 n = __test_n(k); 204 n = __test_n(k);
205 eval (strcat (__init, ";")); 205 eval (cstrcat (__init, ";"));
206 206
207 printf ("n%i=%i ",k, n); 207 printf ("n%i=%i ",k, n);
208 fflush (stdout); 208 fflush (stdout);
209 eval (strcat ("__t=time();", __f1, "; __v1=ans; __t = time()-__t;")); 209 eval (cstrcat ("__t=time();", __f1, "; __v1=ans; __t = time()-__t;"));
210 if (__t < 0.25) 210 if (__t < 0.25)
211 eval (strcat ("__t2=time();", __f1, "; __t2 = time()-__t2;")); 211 eval (cstrcat ("__t2=time();", __f1, "; __t2 = time()-__t2;"));
212 eval (strcat ("__t3=time();", __f1, "; __t3 = time()-__t3;")); 212 eval (cstrcat ("__t3=time();", __f1, "; __t3 = time()-__t3;"));
213 __t = min ([__t, __t2, __t3]); 213 __t = min ([__t, __t2, __t3]);
214 endif 214 endif
215 __tnew(k) = __t; 215 __tnew(k) = __t;
216 216
217 if (! isempty (__f2)) 217 if (! isempty (__f2))
218 eval (strcat ("__t=time();", __f2, "; __v2=ans; __t = time()-__t;")); 218 eval (cstrcat ("__t=time();", __f2, "; __v2=ans; __t = time()-__t;"));
219 if (__t < 0.25) 219 if (__t < 0.25)
220 eval (strcat ("__t2=time();", __f2, "; __t2 = time()-__t2;")); 220 eval (cstrcat ("__t2=time();", __f2, "; __t2 = time()-__t2;"));
221 eval (strcat ("__t3=time();", __f2, "; __t3 = time()-__t3;")); 221 eval (cstrcat ("__t3=time();", __f2, "; __t3 = time()-__t3;"));
222 endif 222 endif
223 __torig(k) = __t; 223 __torig(k) = __t;
224 if (! isinf(__tol)) 224 if (! isinf(__tol))
225 assert (__v1, __v2, __tol); 225 assert (__v1, __v2, __tol);
226 endif 226 endif
255 endif 255 endif
256 256
257 if (doplot && ! isempty (__f2)) 257 if (doplot && ! isempty (__f2))
258 subplot (1, 2, 1); 258 subplot (1, 2, 1);
259 semilogx (__test_n, __torig./__tnew, 259 semilogx (__test_n, __torig./__tnew,
260 strcat ("-*r;", strrep (__f1, ";", "."), "/", 260 cstrcat ("-*r;", strrep (__f1, ";", "."), "/",
261 strrep (__f2, ";", "."), ";"), 261 strrep (__f2, ";", "."), ";"),
262 __test_n, __tnew./__torig, 262 __test_n, __tnew./__torig,
263 strcat ("-*g;", strrep (__f2, ";", "."), "/", 263 cstrcat ("-*g;", strrep (__f2, ";", "."), "/",
264 strrep (__f1, ";", "."), ";")); 264 strrep (__f1, ";", "."), ";"));
265 xlabel ("test length"); 265 xlabel ("test length");
266 title (__f1); 266 title (__f1);
267 ylabel ("speedup ratio"); 267 ylabel ("speedup ratio");
268 268
269 subplot (1, 2, 2); 269 subplot (1, 2, 2);
270 loglog (__test_n, __tnew*1000, 270 loglog (__test_n, __tnew*1000,
271 strcat ("*-g;", strrep (__f1, ";", "."), ";" ), 271 cstrcat ("*-g;", strrep (__f1, ";", "."), ";" ),
272 __test_n, __torig*1000, 272 __test_n, __torig*1000,
273 strcat ("*-r;", strrep (__f2,";","."), ";")); 273 cstrcat ("*-r;", strrep (__f2,";","."), ";"));
274 274
275 xlabel ("test length"); 275 xlabel ("test length");
276 ylabel ("best execution time (ms)"); 276 ylabel ("best execution time (ms)");
277 title (strcat ("init: ", __init)); 277 title (cstrcat ("init: ", __init));
278 278
279 ratio = mean (__torig ./ __tnew); 279 ratio = mean (__torig ./ __tnew);
280 printf ("\n\nMean runtime ratio = %.3g for '%s' vs '%s'\n", 280 printf ("\n\nMean runtime ratio = %.3g for '%s' vs '%s'\n",
281 ratio, __f2, __f1); 281 ratio, __f2, __f1);
282 282
283 elseif (doplot) 283 elseif (doplot)
284 284
285 loglog (__test_n, __tnew*1000, "*-g;execution time;"); 285 loglog (__test_n, __tnew*1000, "*-g;execution time;");
286 xlabel ("test length"); 286 xlabel ("test length");
287 ylabel ("best execution time (ms)"); 287 ylabel ("best execution time (ms)");
288 title (strcat (__f1, " init: ", __init)); 288 title (cstrcat (__f1, " init: ", __init));
289 289
290 endif 290 endif
291 291
292 if (doplot) 292 if (doplot)
293 293