annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19593
diff changeset
1 ## Copyright (C) 2000-2015 Paul Kienzle
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
2 ##
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
3 ## This file is part of Octave.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
4 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
5 ## Octave is free software; you can redistribute it and/or modify it
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
6 ## under the terms of the GNU General Public License as published by
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
7 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
8 ## your option) any later version.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
9 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
10 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
13 ## General Public License for more details.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
14 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
15 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
16 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 7001
diff changeset
17 ## <http://www.gnu.org/licenses/>.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
18
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
19 ## -*- texinfo -*-
10793
be55736a0783 Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents: 10791
diff changeset
20 ## @deftypefn {Function File} {} speed (@var{f}, @var{init}, @var{max_n}, @var{f2}, @var{tol})
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
21 ## @deftypefnx {Function File} {[@var{order}, @var{n}, @var{T_f}, @var{T_f2}] =} speed (@dots{})
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
22 ##
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
23 ## Determine the execution time of an expression (@var{f}) for various input
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
24 ## values (@var{n}).
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
25 ##
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
26 ## The @var{n} are log-spaced from 1 to @var{max_n}. For each @var{n}, an
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
27 ## initialization expression (@var{init}) is computed to create any data needed
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
28 ## for the test. If a second expression (@var{f2}) is given then the
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
29 ## execution times of the two expressions are compared. When called without
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
30 ## output arguments the results are printed to stdout and displayed
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
31 ## graphically.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
32 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
33 ## @table @code
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
34 ## @item @var{f}
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
35 ## The code expression to evaluate.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
36 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
37 ## @item @var{max_n}
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
38 ## The maximum test length to run. The default value is 100. Alternatively,
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
39 ## use @code{[min_n, max_n]} or specify the @var{n} exactly with
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
40 ## @code{[n1, n2, @dots{}, nk]}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
41 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
42 ## @item @var{init}
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
43 ## Initialization expression for function argument values. Use @var{k} for
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
44 ## the test number and @var{n} for the size of the test. This should compute
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
45 ## values for all variables used by @var{f}. Note that @var{init} will be
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
46 ## evaluated first for @math{k = 0}, so things which are constant throughout
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
47 ## the test series can be computed once. The default value is
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
48 ## @code{@var{x} = randn (@var{n}, 1)}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
49 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
50 ## @item @var{f2}
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
51 ## An alternative expression to evaluate, so that the speed of two
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
52 ## expressions can be directly compared. The default is @code{[]}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
53 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
54 ## @item @var{tol}
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
55 ## Tolerance used to compare the results of expression @var{f} and expression
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
56 ## @var{f2}. If @var{tol} is positive, the tolerance is an absolute one.
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
57 ## If @var{tol} is negative, the tolerance is a relative one. The default is
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
58 ## @code{eps}. If @var{tol} is @code{Inf}, then no comparison will be made.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
59 ##
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
60 ## @item @var{order}
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
61 ## The time complexity of the expression @math{O(a*n^p)}. This is a
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
62 ## structure with fields @code{a} and @code{p}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
63 ##
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
64 ## @item @var{n}
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
65 ## The values @var{n} for which the expression was calculated @strong{AND}
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
66 ## the execution time was greater than zero.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
67 ##
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
68 ## @item @var{T_f}
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
69 ## The nonzero execution times recorded for the expression @var{f} in seconds.
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
70 ##
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
71 ## @item @var{T_f2}
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
72 ## The nonzero execution times recorded for the expression @var{f2} in seconds.
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
73 ## If required, the mean time ratio is simply @code{mean (T_f ./ T_f2)}.
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
74 ##
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
75 ## @end table
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
76 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
77 ## The slope of the execution time graph shows the approximate power of the
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
78 ## asymptotic running time @math{O(n^p)}. This power is plotted for the
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
79 ## region over which it is approximated (the latter half of the graph). The
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
80 ## estimated power is not very accurate, but should be sufficient to
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
81 ## determine the general order of an algorithm. It should indicate if, for
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
82 ## example, the implementation is unexpectedly @math{O(n^2)} rather than
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
83 ## @math{O(n)} because it extends a vector each time through the loop rather
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
84 ## than pre-allocating storage. In the current version of Octave, the
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
85 ## following is not the expected @math{O(n)}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
86 ##
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
87 ## @example
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
88 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", "", [1000, 10000])
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
89 ## @end example
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
90 ##
10846
a4f482e66b65 Grammarcheck more of the documentation.
Rik <octave@nomad.inbox5.com>
parents: 10793
diff changeset
91 ## @noindent
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
92 ## But it is if you preallocate the cell array @code{y}:
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
93 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
94 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
95 ## @group
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
96 ## speed ("for i = 1:n, y@{i@} = x(i); endfor", ...
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
97 ## "x = rand (n, 1); y = cell (size (x));", [1000, 10000])
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
98 ## @end group
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
99 ## @end example
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
100 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
101 ## An attempt is made to approximate the cost of individual operations, but
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
102 ## it is wildly inaccurate. You can improve the stability somewhat by doing
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
103 ## more work for each @code{n}. For example:
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
104 ##
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
105 ## @example
8507
cadc73247d65 style fixes
John W. Eaton <jwe@octave.org>
parents: 8506
diff changeset
106 ## speed ("airy(x)", "x = rand (n, 10)", [10000, 100000])
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
107 ## @end example
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
108 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
109 ## When comparing two different expressions (@var{f}, @var{f2}), the slope of
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
110 ## the line on the speedup ratio graph should be larger than 1 if the new
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
111 ## expression is faster. Better algorithms have a shallow slope. Generally,
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
112 ## vectorizing an algorithm will not change the slope of the execution time
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
113 ## graph, but will shift it relative to the original. For example:
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
114 ##
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
115 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
116 ## @group
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
117 ## speed ("sum (x)", "", [10000, 100000], ...
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
118 ## "v = 0; for i = 1:length (x), v += x(i); endfor")
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
119 ## @end group
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
120 ## @end example
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
121 ##
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
122 ## The following is a more complex example. If there was an original version
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
123 ## of @code{xcorr} using for loops and a second version using an FFT, then
11314
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
124 ## one could compare the run speed for various lags as follows, or for a fixed
87f258202b0f speed.m: Overhaul documentation string.
Rik <octave@nomad.inbox5.com>
parents: 10846
diff changeset
125 ## lag with varying vector lengths as follows:
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
126 ##
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
127 ## @example
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
128 ## @group
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
129 ## speed ("xcorr (x, n)", "x = rand (128, 1);", 100,
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
130 ## "xcorr_orig (x, n)", -100*eps)
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
131 ## speed ("xcorr (x, 15)", "x = rand (20+n, 1);", 100,
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
132 ## "xcorr_orig (x, n)", -100*eps)
9051
1bf0ce0930be Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents: 8920
diff changeset
133 ## @end group
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
134 ## @end example
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
135 ##
20162
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
136 ## Assuming one of the two versions is in xcorr_orig, this would compare their
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
137 ## speed and their output values. Note that the FFT version is not exact, so
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
138 ## one must specify an acceptable tolerance on the comparison @code{100*eps}.
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
139 ## In this case, the comparison should be computed relatively, as
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
140 ## @code{abs ((@var{x} - @var{y}) ./ @var{y})} rather than absolutely as
2645f9ef8c88 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19833
diff changeset
141 ## @code{abs (@var{x} - @var{y})}.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
142 ##
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17904
diff changeset
143 ## Type @kbd{example ("speed")} to see some real examples or
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
144 ## @kbd{demo ("speed")} to run them.
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
145 ## @end deftypefn
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
146
8202
cf59d542f33e replace all TODOs and XXXs with FIXMEs
Jaroslav Hajek <highegg@gmail.com>
parents: 7540
diff changeset
147 ## FIXME: consider two dimensional speedup surfaces for functions like kron.
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
148 function [__order, __test_n, __tnew, __torig] = speed (__f1, __init, __max_n = 100, __f2 = "", __tol = eps)
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
149
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
150 if (nargin < 1 || nargin > 6)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5798
diff changeset
151 print_usage ();
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
152 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
153
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
154 if (nargin < 2 || isempty (__init))
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
155 __init = "x = randn (n, 1)";
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
156 endif
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
157
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
158 if (isempty (__max_n))
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
159 __max_n = 100;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
160 endif
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
161
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
162 __numtests = 15;
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
163
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
164 ## Let user specify range of n.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
165 if (isscalar (__max_n))
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
166 __min_n = 1;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
167 assert (__max_n > __min_n);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
168 __test_n = logspace (0, log10 (__max_n), __numtests);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
169 elseif (length (__max_n) == 2)
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
170 [__min_n, __max_n] = deal (__max_n(1), __max_n(2));
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
171 assert (__min_n >= 1);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
172 assert (__max_n > __min_n);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
173 __test_n = logspace (log10 (__min_n), log10 (__max_n), __numtests);
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
174 else
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
175 assert (all (__max_n > 0));
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
176 __test_n = __max_n;
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
177 endif
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
178 ## Force n to be an integer.
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
179 __test_n = unique (round (__test_n));
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
180 assert (__test_n >= 1);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
181
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
182 __torig = __tnew = zeros (size (__test_n));
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
183
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
184 ## Print and plot the data if no output is requested.
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
185 do_display = (nargout == 0);
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
186
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
187 if (do_display)
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
188 disp (["testing " __f1 "\ninit: " __init]);
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
189 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
190
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
191 ## Add semicolon closure to all code fragments in case user has not done so.
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
192 __init(end+1) = ";";
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
193 __f1(end+1) = ";";
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
194 if (! isempty (__f2))
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
195 __f2(end+1) = ";";
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
196 endif
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
197
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
198 ## Make sure the functions are freshly loaded by evaluating them at
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
199 ## test_n(1); first have to initialize the args though.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
200 n = 1;
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
201 k = 0;
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
202 eval (__init);
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
203 eval (__f1);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
204 if (! isempty (__f2))
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
205 eval (__f2);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
206 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
207
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
208 ## Run the tests.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
209 for k = 1:length (__test_n)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
210 n = __test_n(k);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
211 eval (__init);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
212
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
213 if (do_display)
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
214 printf ("n%i = %i ", k, n);
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
215 fflush (stdout);
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
216 endif
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
217
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
218 eval (["__t = time();" __f1 "__v1=ans; __t = time()-__t;"]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
219 if (__t < 0.25)
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
220 eval (["__t2 = time();" __f1 "__t2 = time()-__t2;"]);
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
221 eval (["__t3 = time();" __f1 "__t3 = time()-__t3;"]);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
222 __t = min ([__t, __t2, __t3]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
223 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
224 __tnew(k) = __t;
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
225
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
226 if (! isempty (__f2))
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
227 eval (["__t = time();" __f2 "__v2=ans; __t = time()-__t;"]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
228 if (__t < 0.25)
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
229 eval (["__t2 = time();" __f2 "__t2 = time()-__t2;"]);
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
230 eval (["__t3 = time();" __f2 "__t3 = time()-__t3;"]);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
231 __t = min ([__t, __t2, __t3]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
232 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
233 __torig(k) = __t;
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
234 if (! isinf(__tol))
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
235 assert (__v1, __v2, __tol);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
236 endif
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
237 endif
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
238
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
239 endfor
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
240
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
241 ## Drop times of zero.
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
242 if (isempty (__f2))
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
243 zidx = (__tnew < 100*eps);
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
244 __test_n(zidx) = [];
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
245 __tnew(zidx) = [];
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
246 else
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
247 zidx = (__tnew < 100*eps | __torig < 100*eps);
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
248 __test_n(zidx) = [];
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
249 __tnew(zidx) = [];
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
250 __torig(zidx) = [];
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
251 endif
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
252
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
253 if (isempty (__test_n))
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
254 error (["speed: All running times were zero.\n",
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
255 "error: speed: Choose larger MAX_N or do more work per function evaluation"]);
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
256 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
257
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
258 ## Approximate time complexity and return it if requested.
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
259 tailidx = ceil (length (__test_n)/2):length (__test_n);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
260 p = polyfit (log (__test_n(tailidx)), log (__tnew(tailidx)), 1);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
261 if (nargout > 0)
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
262 __order.p = p(1);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
263 __order.a = exp (p(2));
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
264 endif
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
265
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
266 if (do_display)
6430
215b141470b4 [project @ 2007-03-21 20:58:08 by dbateman]
dbateman
parents: 6429
diff changeset
267 figure;
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
268 ## Strip semicolon added to code fragments before displaying
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17904
diff changeset
269 __init(end) = "";
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17904
diff changeset
270 __f1(end) = "";
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
271 if (! isempty (__f2))
19593
446c46af4b42 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 17904
diff changeset
272 __f2(end) = "";
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
273 endif
6430
215b141470b4 [project @ 2007-03-21 20:58:08 by dbateman]
dbateman
parents: 6429
diff changeset
274 endif
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
275
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
276 if (do_display && isempty (__f2))
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
277
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
278 loglog (__test_n, __tnew*1000, "*-g;execution time;");
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
279 xlabel ("test length");
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
280 ylabel ("best execution time (ms)");
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
281 title ({__f1, ["init: " __init]});
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
282
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
283 elseif (do_display)
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
284
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
285 subplot (1, 2, 1);
11587
c792872f8942 all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
286 semilogx (__test_n, __torig./__tnew,
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
287 ["-*r;" strrep(__f1, ";", ".") " / " strrep(__f2, ";", ".") ";"],
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
288 __test_n, __tnew./__torig,
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
289 ["-*g;", strrep(__f2, ";", ".") " / " strrep(__f1, ";", ".") ";"]);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
290 title ("Speedup Ratio");
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
291 xlabel ("test length");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
292 ylabel ("speedup ratio");
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
293
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
294 subplot (1, 2, 2);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
295 loglog (__test_n, __tnew*1000,
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
296 ["*-g;" strrep(__f1,";",".") ";"],
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 9051
diff changeset
297 __test_n, __torig*1000,
16994
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
298 ["*-r;" strrep(__f2,";",".") ";"]);
333243133364 Use matrix concatenation for strings, rather than cstrcat(), for clarity and performance.
Rik <rik@octave.org>
parents: 14868
diff changeset
299 title ({"Execution Times", ["init: " __init]});
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
300 xlabel ("test length");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
301 ylabel ("best execution time (ms)");
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
302
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
303 ratio = mean (__torig ./ __tnew);
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
304 printf ("\n\nMean runtime ratio = %.3g for '%s' vs '%s'\n",
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
305 ratio, __f2, __f1);
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
306
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
307 endif
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
308
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
309 if (do_display)
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
310
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
311 ## Plot time complexity approximation (using milliseconds).
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
312 figure; # Open second plot window
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
313
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
314 order = round (10*p(1))/10;
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
315 if (order >= 0.1)
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
316 order = sprintf ("O(n^%g)", order);
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
317 else
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
318 order = "O(1)";
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
319 endif
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
320 v = polyval (p, log (__test_n(tailidx)));
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
321
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
322 loglog (__test_n(tailidx), exp (v) * 1000, sprintf ("b;%s;", order));
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
323 title ({"Time Complexity", __f1});
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
324 xlabel ("test length");
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
325
8506
bc982528de11 comment style fixes
John W. Eaton <jwe@octave.org>
parents: 8202
diff changeset
326 ## Get base time to 1 digit of accuracy.
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
327 dt = exp (p(2));
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
328 dt = floor (dt/10^floor (log10 (dt)))*10^floor (log10 (dt));
6494
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
329 if (log10 (dt) >= -0.5)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
330 time = sprintf ("%g s", dt);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
331 elseif (log10 (dt) >= -3.5)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
332 time = sprintf ("%g ms", dt*1e3);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
333 elseif (log10 (dt) >= -6.5)
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
334 time = sprintf ("%g us", dt*1e6);
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
335 else
76a1a953533d [project @ 2007-04-05 16:09:03 by jwe]
jwe
parents: 6430
diff changeset
336 time = sprintf ("%g ns", dt*1e9);
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
337 endif
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
338
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
339 ## Display nicely formatted complexity.
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
340 printf ("\nFor %s:\n", __f1);
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
341 printf (" asymptotic power: %s\n", order);
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
342 printf (" approximate time per operation: %s\n", time);
5798
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
343
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
344 endif
7e7ed81f5566 [project @ 2006-05-09 17:24:33 by jwe]
jwe
parents: 5589
diff changeset
345
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
346 endfunction
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
347
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
348
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
349 ## FIXME: Demos with declared functions do not work. See bug #31815.
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
350 ## A workaround has been hacked by not declaring the functions
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
351 ## but using eval to create them in the proper context.
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
352 ## Unfortunately, we can't remove them from the user's workspace
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
353 ## because of another bug (#34497).
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
354 %!demo
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
355 %! fstr_build_orig = cstrcat (
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
356 %! "function x = build_orig (n)\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
357 %! " ## extend the target vector on the fly\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
358 %! " for i=0:n-1, x([1:100]+i*100) = 1:100; endfor\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
359 %! "endfunction");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
360 %! fstr_build = cstrcat (
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
361 %! "function x = build (n)\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
362 %! " ## preallocate the target vector\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
363 %! " x = zeros (1, n*100);\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
364 %! " for i=0:n-1, x([1:100]+i*100) = 1:100; endfor\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
365 %! "endfunction");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
366 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
367 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
368 %! disp (fstr_build_orig);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
369 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
370 %! disp (fstr_build);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
371 %! disp ("-----------------------");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
372 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
373 %! ## Eval functions strings to create them in the current context
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
374 %! eval (fstr_build_orig);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
375 %! eval (fstr_build);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
376 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
377 %! disp ("Preallocated vector test.\nThis takes a little while...");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
378 %! speed ("build (n)", "", 1000, "build_orig (n)");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
379 %! clear -f build build_orig
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
380 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
381 %! disp ("Note how much faster it is to pre-allocate a vector.");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
382 %! disp ("Notice the peak speedup ratio.");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
383
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
384 %!demo
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
385 %! fstr_build_orig = cstrcat (
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
386 %! "function x = build_orig (n)\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
387 %! " for i=0:n-1, x([1:100]+i*100) = 1:100; endfor\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
388 %! "endfunction");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
389 %! fstr_build = cstrcat (
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
390 %! "function x = build (n)\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
391 %! " idx = [1:100]';\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
392 %! " x = idx(:,ones(1,n));\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
393 %! " x = reshape (x, 1, n*100);\n",
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
394 %! "endfunction");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
395 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
396 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
397 %! disp (fstr_build_orig);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
398 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
399 %! disp (fstr_build);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
400 %! disp ("-----------------------");
5589
f812a0680d05 [project @ 2006-01-06 00:14:42 by jwe]
jwe
parents:
diff changeset
401 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
402 %! ## Eval functions strings to create them in the current context
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
403 %! eval (fstr_build_orig);
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
404 %! eval (fstr_build);
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
405 %!
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
406 %! disp ("Vectorized test.\nThis takes a little while...");
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
407 %! speed ("build (n)", "", 1000, "build_orig (n)");
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
408 %! clear -f build build_orig
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
409 %! disp ("-----------------------");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
410 %! disp ("This time, the for loop is done away with entirely.");
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
411 %! disp ("Notice how much bigger the speedup is than in example 1.");
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
412
17904
817da22e58ed speed.m: Change %!test blocks to %!xtest blocks.
Rik <rik@octave.org>
parents: 17744
diff changeset
413 ## FIXME: Tests are known to fail on operating systems with low resolution
817da22e58ed speed.m: Change %!test blocks to %!xtest blocks.
Rik <rik@octave.org>
parents: 17744
diff changeset
414 ## timers such as MinGW. Therefore, tests are made xtests so that false
817da22e58ed speed.m: Change %!test blocks to %!xtest blocks.
Rik <rik@octave.org>
parents: 17744
diff changeset
415 ## failures are not reported. However, it might be better to either
817da22e58ed speed.m: Change %!test blocks to %!xtest blocks.
Rik <rik@octave.org>
parents: 17744
diff changeset
416 ## force the tests to do more work, or use %!testif to check the OS.
817da22e58ed speed.m: Change %!test blocks to %!xtest blocks.
Rik <rik@octave.org>
parents: 17744
diff changeset
417 %!xtest
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
418 %! [order, n, T_f1, T_f2] = speed ("airy (x)", "x = rand (n, 10)", [100, 1000]);
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
419 %! assert (isstruct (order));
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
420 %! assert (size (order), [1, 1]);
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
421 %! assert (fieldnames (order), {"p"; "a"});
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
422 %! assert (isnumeric (n));
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
423 %! assert (length (n) > 10);
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
424 %! assert (isnumeric (T_f1));
13276
d5c8c2fe2eed speed.m: Further fixes for 2 speed tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13274
diff changeset
425 %! assert (size (T_f1), size (n));
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
426 %! assert (isnumeric (T_f2));
13276
d5c8c2fe2eed speed.m: Further fixes for 2 speed tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13274
diff changeset
427 %! assert (length (T_f2) > 10);
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
428
13283
5d3d802c772e speed.m: Overhaul code to fix broken demos and tests (Bug #34234, Bug #31815)
Rik <octave@nomad.inbox5.com>
parents: 13276
diff changeset
429 %!xtest
13276
d5c8c2fe2eed speed.m: Further fixes for 2 speed tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13274
diff changeset
430 %! [order, n, T_f1, T_f2] = speed ("sum (x)", "", [100, 1000], "v = 0; for i = 1:length (x), v += x(i); endfor");
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
431 %! assert (isstruct (order));
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
432 %! assert (size (order), [1, 1]);
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
433 %! assert (fieldnames (order), {"p"; "a"});
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
434 %! assert (isnumeric (n));
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
435 %! assert (length (n) > 10);
13065
1ca3cde15b18 codepsprint: tests for testfun functions
John W. Eaton <jwe@octave.org>
parents: 11587
diff changeset
436 %! assert (isnumeric (T_f1));
13276
d5c8c2fe2eed speed.m: Further fixes for 2 speed tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13274
diff changeset
437 %! assert (size (T_f1), size (n));
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
438 %! assert (isnumeric (T_f2));
13276
d5c8c2fe2eed speed.m: Further fixes for 2 speed tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13274
diff changeset
439 %! assert (length (T_f2) > 10);
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
440
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19697
diff changeset
441 ## Test input validation
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
442 %!error speed ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14237
diff changeset
443 %!error speed (1, 2, 3, 4, 5, 6, 7)
13274
b48e11427ac0 speed.m: Fix 2 intermittently failing tests (Bug #34234)
Rik <octave@nomad.inbox5.com>
parents: 13065
diff changeset
444