Functions | |
endif | if (nargin< 2||isempty(__init)) __init |
if (isscalar(__max_n)) __min_n | |
assert (__max_n > __min_n) | |
elseif (length(__max_n)==2) __min_n | |
assert (__min_n >=1) | |
assert (__test_n >=1) | |
disp (cstrcat("testing ", __f1,"\ninit: ", __init)) | |
eval (cstrcat(__init,";")) | |
if (!isempty(__f2)) eval(cstrcat(__f2 | |
endif | eval (cstrcat(__f1,";")) |
printf ("n%i = %i ", k, n) | |
fflush (stdout) | |
eval (cstrcat("__t = time();", __f1,"; __v1=ans; __t = time()-__t;")) | |
eval (cstrcat("__t3 = time();", __f1,"; __t3 = time()-__t3;")) | |
endif | __tnew (k) |
eval (cstrcat("__t3 = time();", __f2,"; __t3 = time()-__t3;")) | |
endif | __torig (k) |
if (!isinf(__tol)) assert(__v1 | |
__test_n (zidx) | |
__tnew (zidx) | |
__torig (zidx) | |
if (nargout > 0) __order.p | |
if (doplot) figure | |
endif | if (doplot &&!isempty(__f2)) subplot(1 |
endif | semilogx (__test_n, __torig./__tnew, cstrcat("-*r;", strrep(__f1,";","."),"/", strrep(__f2,";","."),";"), __test_n, __tnew./__torig, cstrcat("-*g;", strrep(__f2,";","."),"/", strrep(__f1,";","."),";")) |
xlabel ("test length") | |
title (__f1) | |
ylabel ("speedup ratio") | |
subplot (1, 2, 2) | |
loglog (__test_n, __tnew *1000, cstrcat("*-g;", strrep(__f1,";","."),";"), __test_n, __torig *1000, cstrcat("*-r;", strrep(__f2,";","."),";")) | |
ylabel ("best execution time (ms)") | |
title (cstrcat("init: ", __init)) | |
elseif (doplot) loglog(__test_n | |
id | g () |
title (cstrcat(__f1," init: ", __init)) | |
loglog (__test_n(tailidx), exp(v)*1000, sprintf("b;%s;", order)) | |
if (log10(dt) >=-0.5) time | |
elseif (log10(dt) >=-3.5) time | |
elseif (log10(dt) >=-6.5) time | |
endif | printf ("\nFor %s:\n", __f1) |
printf (" asymptotic power: %s\n", order) | |
printf (" approximate time per operation: %s\n", time) | |
endif endfunction!demo if!function | x ([1:10]+i *10) |
!try | !if (prefer_column_vectors) |
endfor!endfunction | !disp ("-----------------------") |
!disp ("Preallocated vector test.\nThis takes a little while...") | |
!speed ('build(n)', '', 1000, 'build_orig(n)') | |
!clear build build_orig | !disp ("Note how much faster it is to pre-allocate a vector.") |
!disp ("Notice the peak speedup ratio.") | |
!disp ("Vectorized test. This takes a little while...") | |
!disp ("This time, the for loop is done away with entirely.") | |
!disp ("Notice how much bigger the speedup is then in example 1.") | |
Variables | |
function [__order, __test_n, __tnew, __torig] | |
endif | __numtests = 15 |
__test_n = logspace (0, log10 (__max_n), __numtests) | |
__max_n = __max_n(2) | |
__torig = __tnew = zeros (size (__test_n)) | |
n = 1 | |
k = 0 | |
__f1 | |
__t2 = time()-__t2 | |
__t = min ([__t, __t2, __t3]) | |
__f2 | |
__v2 = ans | |
__tol | |
else | zidx = (__tnew < 100*eps) |
endif | tailidx = ceil(length(__test_n)/2):length(__test_n) |
p = polyfit (log (__test_n(tailidx)), log (__tnew(tailidx)), 1) | |
__order | a = exp (p(2)) |
endif | doplot = (nargout == 0) |
ratio = mean (__torig ./ __tnew) | |
execution | time = sprintf ("%g ns", dt*1e9) |
v = polyval (p, log (__test_n(tailidx))) | |
dt = exp (p(2)) | |
endif endfunction!demo if!function | x |
endif!catch!end!for | i = 0:n-1 |
!type | build_orig |
!type | build |
!x = idx(:,ones(1,n)) |
!disp | ( | "Vectorized test. This takes a little while..." | ) |
!disp | ( | "Notice the peak speedup ratio." | ) |
! clear build build_orig !disp | ( | "Note how much faster it is to pre-allocate a vector." | ) |
!disp | ( | "Preallocated vector test.\nThis takes a little while..." | ) |
endfor ! endfunction !disp | ( | "-----------------------" | ) |
! try !if | ( | prefer_column_vectors | ) |
!speed | ( | 'build(n)' | , | |
'' | , | |||
1000 | , | |||
'build_orig(n)' | ||||
) |
__test_n | ( | zidx | ) |
__tnew | ( | zidx | ) |
__torig | ( | zidx | ) |
assert | ( | __test_n >= | 1 | ) |
assert | ( | __min_n >= | 1 | ) |
assert | ( | __max_n | , | |
__min_n | ||||
) |
disp | ( | cstrcat("testing ", __f1,"\ninit: ", __init) | ) |
elseif | ( | log10(dt) >=-6. | 5 | ) |
elseif | ( | log10(dt) >=-3. | 5 | ) |
elseif | ( | doplot | ) |
elseif | ( | length(__max_n) | = =2 |
) |
eval | ( | cstrcat(__init,";") | ) |
fflush | ( | stdout | ) |
id g | ( | ) | [virtual] |
if | ( | log10(dt) >=-0. | 5 | ) |
if | ( | doplot | ) |
if | ( | nargout | , | |
0 | ||||
) |
if | ( | ! | isinf__tol | ) |
if | ( | ! | isempty__f2 | ) |
if | ( | isscalar(__max_n) | ) |
endif if | ( | ) |
loglog | ( | __test_n(tailidx) | , | |
exp(v)* | 1000, | |||
sprintf("b;%s;", order) | ||||
) |
loglog | ( | __test_n | , | |
__tnew * | 1000, | |||
cstrcat("*-g;", strrep(__f1,";","."),";") | , | |||
__test_n | , | |||
__torig * | 1000, | |||
cstrcat("*-r;", strrep(__f2,";","."),";") | ||||
) |
printf | ( | " asymptotic power: %s\n" | , | |
order | ||||
) |
printf | ( | ) |
endif semilogx | ( | __test_n | , | |
__torig./ | __tnew, | |||
cstrcat("-*r;", strrep(__f1,";","."),"/", strrep(__f2,";","."),";") | , | |||
__test_n | , | |||
__tnew./ | __torig, | |||
cstrcat("-*g;", strrep(__f2,";","."),"/", strrep(__f1,";","."),";") | ||||
) |
subplot | ( | 1 | , | |
2 | , | |||
2 | ||||
) |
title | ( | cstrcat(__f1," init: ", __init) | ) |
title | ( | cstrcat("init: ", __init) | ) |
title | ( | __f1 | ) |
endif endfunction !demo if ! function x | ( | [1:10] +i * | 10 | ) |
xlabel | ( | "test length" | ) |
ylabel | ( | "speedup ratio" | ) |
!x = idx(:,ones(1,n)) |
endif __numtests = 15 |
endif __test_n = logspace (0, log10 (__max_n), __numtests) |
__torig = __tnew = zeros (size (__test_n)) |
__v2 = ans |
__order a = exp (p(2)) |
dt = exp (p(2)) |
function[__order, __test_n, __tnew, __torig] |
n = 1 |
ratio = mean (__torig ./ __tnew) |
v = polyval (p, log (__test_n(tailidx))) |