Mercurial > octave-antonio
comparison scripts/testfun/speed.m @ 20162:2645f9ef8c88 stable
doc: Update more docstrings to have one sentence summary as first line.
Reviewed specfun, special-matrix, testfun, and time script directories.
* scripts/specfun/expint.m, scripts/specfun/isprime.m,
scripts/specfun/legendre.m, scripts/specfun/primes.m,
scripts/specfun/reallog.m, scripts/specfun/realsqrt.m,
scripts/special-matrix/gallery.m, scripts/special-matrix/hadamard.m,
scripts/special-matrix/hankel.m, scripts/special-matrix/hilb.m,
scripts/special-matrix/invhilb.m, scripts/special-matrix/magic.m,
scripts/special-matrix/pascal.m, scripts/special-matrix/rosser.m,
scripts/special-matrix/toeplitz.m, scripts/special-matrix/vander.m,
scripts/special-matrix/wilkinson.m, scripts/testfun/assert.m,
scripts/testfun/demo.m, scripts/testfun/example.m, scripts/testfun/fail.m,
scripts/testfun/rundemos.m, scripts/testfun/runtests.m,
scripts/testfun/speed.m, scripts/time/asctime.m, scripts/time/calendar.m,
scripts/time/clock.m, scripts/time/ctime.m, scripts/time/datenum.m,
scripts/time/datestr.m, scripts/time/datevec.m, scripts/time/etime.m,
scripts/time/is_leap_year.m, scripts/time/now.m, scripts/time/weekday.m:
Update more docstrings to have one sentence summary as first line.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 May 2015 17:00:11 -0700 |
parents | 9fc020886ae9 |
children |
comparison
equal
deleted
inserted
replaced
20160:03b9d17a2d95 | 20162:2645f9ef8c88 |
---|---|
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} speed (@var{f}, @var{init}, @var{max_n}, @var{f2}, @var{tol}) | 20 ## @deftypefn {Function File} {} speed (@var{f}, @var{init}, @var{max_n}, @var{f2}, @var{tol}) |
21 ## @deftypefnx {Function File} {[@var{order}, @var{n}, @var{T_f}, @var{T_f2}] =} speed (@dots{}) | 21 ## @deftypefnx {Function File} {[@var{order}, @var{n}, @var{T_f}, @var{T_f2}] =} speed (@dots{}) |
22 ## | 22 ## |
23 ## Determine the execution time of an expression (@var{f}) for various input | 23 ## Determine the execution time of an expression (@var{f}) for various input |
24 ## values (@var{n}). The @var{n} are log-spaced from 1 to @var{max_n}. For | 24 ## values (@var{n}). |
25 ## each @var{n}, an initialization expression (@var{init}) is computed to | 25 ## |
26 ## create any data needed for the test. If a second expression (@var{f2}) is | 26 ## The @var{n} are log-spaced from 1 to @var{max_n}. For each @var{n}, an |
27 ## given then the execution times of the two expressions are compared. When | 27 ## initialization expression (@var{init}) is computed to create any data needed |
28 ## called without output arguments the results are printed to stdout and | 28 ## for the test. If a second expression (@var{f2}) is given then the |
29 ## displayed graphically. | 29 ## execution times of the two expressions are compared. When called without |
30 ## output arguments the results are printed to stdout and displayed | |
31 ## graphically. | |
30 ## | 32 ## |
31 ## @table @code | 33 ## @table @code |
32 ## @item @var{f} | 34 ## @item @var{f} |
33 ## The code expression to evaluate. | 35 ## The code expression to evaluate. |
34 ## | 36 ## |
36 ## The maximum test length to run. The default value is 100. Alternatively, | 38 ## The maximum test length to run. The default value is 100. Alternatively, |
37 ## use @code{[min_n, max_n]} or specify the @var{n} exactly with | 39 ## use @code{[min_n, max_n]} or specify the @var{n} exactly with |
38 ## @code{[n1, n2, @dots{}, nk]}. | 40 ## @code{[n1, n2, @dots{}, nk]}. |
39 ## | 41 ## |
40 ## @item @var{init} | 42 ## @item @var{init} |
41 ## Initialization expression for function argument values. Use @var{k} | 43 ## Initialization expression for function argument values. Use @var{k} for |
42 ## for the test number and @var{n} for the size of the test. This should | 44 ## the test number and @var{n} for the size of the test. This should compute |
43 ## compute values for all variables used by @var{f}. Note that @var{init} will | 45 ## values for all variables used by @var{f}. Note that @var{init} will be |
44 ## be evaluated first for @math{k = 0}, so things which are constant throughout | 46 ## evaluated first for @math{k = 0}, so things which are constant throughout |
45 ## the test series can be computed once. The default value is | 47 ## the test series can be computed once. The default value is |
46 ## @code{@var{x} = randn (@var{n}, 1)}. | 48 ## @code{@var{x} = randn (@var{n}, 1)}. |
47 ## | 49 ## |
48 ## @item @var{f2} | 50 ## @item @var{f2} |
49 ## An alternative expression to evaluate, so that the speed of two | 51 ## An alternative expression to evaluate, so that the speed of two |
54 ## @var{f2}. If @var{tol} is positive, the tolerance is an absolute one. | 56 ## @var{f2}. If @var{tol} is positive, the tolerance is an absolute one. |
55 ## If @var{tol} is negative, the tolerance is a relative one. The default is | 57 ## If @var{tol} is negative, the tolerance is a relative one. The default is |
56 ## @code{eps}. If @var{tol} is @code{Inf}, then no comparison will be made. | 58 ## @code{eps}. If @var{tol} is @code{Inf}, then no comparison will be made. |
57 ## | 59 ## |
58 ## @item @var{order} | 60 ## @item @var{order} |
59 ## The time complexity of the expression @math{O(a*n^p)}. This | 61 ## The time complexity of the expression @math{O(a*n^p)}. This is a |
60 ## is a structure with fields @code{a} and @code{p}. | 62 ## structure with fields @code{a} and @code{p}. |
61 ## | 63 ## |
62 ## @item @var{n} | 64 ## @item @var{n} |
63 ## The values @var{n} for which the expression was calculated @strong{AND} | 65 ## The values @var{n} for which the expression was calculated @strong{AND} |
64 ## the execution time was greater than zero. | 66 ## the execution time was greater than zero. |
65 ## | 67 ## |
70 ## The nonzero execution times recorded for the expression @var{f2} in seconds. | 72 ## The nonzero execution times recorded for the expression @var{f2} in seconds. |
71 ## If required, the mean time ratio is simply @code{mean (T_f ./ T_f2)}. | 73 ## If required, the mean time ratio is simply @code{mean (T_f ./ T_f2)}. |
72 ## | 74 ## |
73 ## @end table | 75 ## @end table |
74 ## | 76 ## |
75 ## The slope of the execution time graph shows the approximate | 77 ## The slope of the execution time graph shows the approximate power of the |
76 ## power of the asymptotic running time @math{O(n^p)}. This | 78 ## asymptotic running time @math{O(n^p)}. This power is plotted for the |
77 ## power is plotted for the region over which it is approximated | 79 ## region over which it is approximated (the latter half of the graph). The |
78 ## (the latter half of the graph). The estimated power is not | 80 ## estimated power is not very accurate, but should be sufficient to |
79 ## very accurate, but should be sufficient to determine the | 81 ## determine the general order of an algorithm. It should indicate if, for |
80 ## general order of an algorithm. It should indicate if, for | 82 ## example, the implementation is unexpectedly @math{O(n^2)} rather than |
81 ## example, the implementation is unexpectedly @math{O(n^2)} | 83 ## @math{O(n)} because it extends a vector each time through the loop rather |
82 ## rather than @math{O(n)} because it extends a vector each | 84 ## than pre-allocating storage. In the current version of Octave, the |
83 ## time through the loop rather than pre-allocating storage. | 85 ## following is not the expected @math{O(n)}. |
84 ## In the current version of Octave, the following is not the | |
85 ## expected @math{O(n)}. | |
86 ## | 86 ## |
87 ## @example | 87 ## @example |
88 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", "", [1000, 10000]) | 88 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", "", [1000, 10000]) |
89 ## @end example | 89 ## @end example |
90 ## | 90 ## |
96 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", ... | 96 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", ... |
97 ## "x = rand (n, 1); y = cell (size (x));", [1000, 10000]) | 97 ## "x = rand (n, 1); y = cell (size (x));", [1000, 10000]) |
98 ## @end group | 98 ## @end group |
99 ## @end example | 99 ## @end example |
100 ## | 100 ## |
101 ## An attempt is made to approximate the cost of individual | 101 ## An attempt is made to approximate the cost of individual operations, but |
102 ## operations, but it is wildly inaccurate. You can improve the | 102 ## it is wildly inaccurate. You can improve the stability somewhat by doing |
103 ## stability somewhat by doing more work for each @code{n}. For | 103 ## more work for each @code{n}. For example: |
104 ## example: | |
105 ## | 104 ## |
106 ## @example | 105 ## @example |
107 ## speed ("airy(x)", "x = rand (n, 10)", [10000, 100000]) | 106 ## speed ("airy(x)", "x = rand (n, 10)", [10000, 100000]) |
108 ## @end example | 107 ## @end example |
109 ## | 108 ## |
110 ## When comparing two different expressions (@var{f}, @var{f2}), the slope | 109 ## When comparing two different expressions (@var{f}, @var{f2}), the slope of |
111 ## of the line on the speedup ratio graph should be larger than 1 if the new | 110 ## the line on the speedup ratio graph should be larger than 1 if the new |
112 ## expression is faster. Better algorithms have a shallow slope. Generally, | 111 ## expression is faster. Better algorithms have a shallow slope. Generally, |
113 ## vectorizing an algorithm will not change the slope of the execution | 112 ## vectorizing an algorithm will not change the slope of the execution time |
114 ## time graph, but will shift it relative to the original. For | 113 ## graph, but will shift it relative to the original. For example: |
115 ## example: | |
116 ## | 114 ## |
117 ## @example | 115 ## @example |
118 ## @group | 116 ## @group |
119 ## speed ("sum (x)", "", [10000, 100000], ... | 117 ## speed ("sum (x)", "", [10000, 100000], ... |
120 ## "v = 0; for i = 1:length (x), v += x(i); endfor") | 118 ## "v = 0; for i = 1:length (x), v += x(i); endfor") |
133 ## speed ("xcorr (x, 15)", "x = rand (20+n, 1);", 100, | 131 ## speed ("xcorr (x, 15)", "x = rand (20+n, 1);", 100, |
134 ## "xcorr_orig (x, n)", -100*eps) | 132 ## "xcorr_orig (x, n)", -100*eps) |
135 ## @end group | 133 ## @end group |
136 ## @end example | 134 ## @end example |
137 ## | 135 ## |
138 ## Assuming one of the two versions is in xcorr_orig, this | 136 ## Assuming one of the two versions is in xcorr_orig, this would compare their |
139 ## would compare their speed and their output values. Note that the | 137 ## speed and their output values. Note that the FFT version is not exact, so |
140 ## FFT version is not exact, so one must specify an acceptable tolerance on | 138 ## one must specify an acceptable tolerance on the comparison @code{100*eps}. |
141 ## the comparison @code{100*eps}. In this case, the comparison should be | 139 ## In this case, the comparison should be computed relatively, as |
142 ## computed relatively, as @code{abs ((@var{x} - @var{y}) ./ @var{y})} rather | 140 ## @code{abs ((@var{x} - @var{y}) ./ @var{y})} rather than absolutely as |
143 ## than absolutely as @code{abs (@var{x} - @var{y})}. | 141 ## @code{abs (@var{x} - @var{y})}. |
144 ## | 142 ## |
145 ## Type @kbd{example ("speed")} to see some real examples or | 143 ## Type @kbd{example ("speed")} to see some real examples or |
146 ## @kbd{demo ("speed")} to run them. | 144 ## @kbd{demo ("speed")} to run them. |
147 ## @end deftypefn | 145 ## @end deftypefn |
148 | 146 |