comparison scripts/testfun/speed.m @ 6429:6ff2d413cf58

[project @ 2007-03-21 20:13:03 by dbateman]
author dbateman
date Wed, 21 Mar 2007 20:13:03 +0000
parents 34f96dd5441b
children 215b141470b4
comparison
equal deleted inserted replaced
6428:1a59ba7d32f0 6429:6ff2d413cf58
49 ## @item @var{tol} 49 ## @item @var{tol}
50 ## If @var{tol} is @code{Inf}, then no comparison will be made between the 50 ## If @var{tol} is @code{Inf}, then no comparison will be made between the
51 ## results of expression @var{f} and expression @var{f2}. Otherwise, 51 ## results of expression @var{f} and expression @var{f2}. Otherwise,
52 ## expression @var{f} should produce a value @var{v} and expression @var{f2} 52 ## expression @var{f} should produce a value @var{v} and expression @var{f2}
53 ## should produce a value @var{v2}, and these shall be compared using 53 ## should produce a value @var{v2}, and these shall be compared using
54 ## @code{assert(@var{v},@var{v2},@var{tol})}. The default is 54 ## @code{assert(@var{v},@var{v2},@var{tol})}. If @var{tol} is positive,
55 ## @code{eps}. 55 ## the tolerance is assumed to be absolutr. If @var{tol} is negative,
56 ## the tolerance is assumed to be relative. The default is @code{eps}.
56 ## 57 ##
57 ## @item @var{order} 58 ## @item @var{order}
58 ## The time complexity of the expression @code{O(a n^p)}. This 59 ## The time complexity of the expression @code{O(a n^p)}. This
59 ## is a structure with fields @code{a} and @code{p}. 60 ## is a structure with fields @code{a} and @code{p}.
60 ## 61 ##
120 ## run speed for various lags as follows, or for a fixed lag with varying 121 ## run speed for various lags as follows, or for a fixed lag with varying
121 ## vector lengths as follows: 122 ## vector lengths as follows:
122 ## 123 ##
123 ## @example 124 ## @example
124 ## speed("v=xcorr(x,n)", "x=rand(128,1);", 100, ... 125 ## speed("v=xcorr(x,n)", "x=rand(128,1);", 100, ...
125 ## "v2=xcorr_orig(x,n)", 100*eps,'rel') 126 ## "v2=xcorr_orig(x,n)", -100*eps)
126 ## speed("v=xcorr(x,15)", "x=rand(20+n,1);", 100, ... 127 ## speed("v=xcorr(x,15)", "x=rand(20+n,1);", 100, ...
127 ## "v2=xcorr_orig(x,n)", 100*eps,'rel') 128 ## "v2=xcorr_orig(x,n)", -100*eps)
128 ## @end example 129 ## @end example
129 ## 130 ##
130 ## Assuming one of the two versions is in @var{xcorr_orig}, this would 131 ## Assuming one of the two versions is in @var{xcorr_orig}, this would
131 ## would compare their speed and their output values. Note that the 132 ## would compare their speed and their output values. Note that the
132 ## FFT version is not exact, so we specify an acceptable tolerance on 133 ## FFT version is not exact, so we specify an acceptable tolerance on
313 %! disp("-----------------------"); 314 %! disp("-----------------------");
314 %! type build; 315 %! type build;
315 %! disp("-----------------------"); 316 %! disp("-----------------------");
316 %! 317 %!
317 %! disp("Preallocated vector test.\nThis takes a little while..."); 318 %! disp("Preallocated vector test.\nThis takes a little while...");
318 %! speed('build', 'build_orig', 1000, 'v=n;'); 319 %! speed('build(n)', '', 1000, 'build_orig(n)');
319 %! clear build build_orig 320 %! clear build build_orig
320 %! disp("Note how much faster it is to pre-allocate a vector."); 321 %! disp("Note how much faster it is to pre-allocate a vector.");
321 %! disp("Notice the peak speedup ratio."); 322 %! disp("Notice the peak speedup ratio.");
322 %! clear build build_orig
323 %! endif 323 %! endif
324 324
325 %!demo if 1 325 %!demo if 1
326 %! function x = build_orig(n) 326 %! function x = build_orig(n)
327 %! for i=0:n-1, x([1:10]+i*10) = 1:10; endfor 327 %! for i=0:n-1, x([1:10]+i*10) = 1:10; endfor
341 %! disp("-----------------------"); 341 %! disp("-----------------------");
342 %! type build; 342 %! type build;
343 %! disp("-----------------------"); 343 %! disp("-----------------------");
344 %! 344 %!
345 %! disp("Vectorized test. This takes a little while..."); 345 %! disp("Vectorized test. This takes a little while...");
346 %! speed('build', 'build_orig', 1000, 'v=n;'); 346 %! speed('build(n)', '', 1000, 'build_orig(n)');
347 %! clear build build_orig 347 %! clear build build_orig
348 %! disp("-----------------------"); 348 %! disp("-----------------------");
349 %! disp("This time, the for loop is done away with entirely."); 349 %! disp("This time, the for loop is done away with entirely.");
350 %! disp("Notice how much bigger the speedup is then in example 1."); 350 %! disp("Notice how much bigger the speedup is then in example 1.");
351 %! endif 351 %! endif