1 % Copyright (C) 2009 VZLU Prague
3 % This file is part of OctaveForge.
5 % OctaveForge is free software; you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation; either version 2 of the License, or
8 % (at your option) any later version.
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
15 % You should have received a copy of the GNU General Public License
16 % along with this software; see the file COPYING. If not, see
17 % <http://www.gnu.org/licenses/>.
20 % function benchmark_index (n, rep)
22 % Test speed of array indexing.
26 % rep = number of repeats
29 % time_slice1 = time for a(i:j)
30 % time_slice1s = time for a(i:k:j)
31 % time_slice1v = time for a(idx)
32 % time_slice2c = time for a(:,i:j)
33 % time_slice2r = time for a(i:j,:)
34 % time_slice2cv = time for a(:,idx)
35 % time_slice2rv = time for a(idx,:)
36 % time_slicenc = time for a(:,:,i:j,k)
37 % time_slicend = time for a(:,:,k,i:j)
38 % time_slicens = time for a(i,j,k,:)
39 % time_spreadr = time for a(ones(1, k), :), a row vector
40 % time_spreadc = time for a(:, ones(1, k)), a column vector
43 function results = benchmark_index (n, rep)
45 benchutil_default_arg ('n', 4e6);
46 benchutil_default_arg ('rep', 100);
48 benchutil_initialize (mfilename)
60 benchutil_set_result ('time_slice1')
69 benchutil_set_result ('time_slice1s')
71 idx = cumsum (rand (1, n));
72 idx = ceil (idx / idx(end) * n);
79 benchutil_set_result ('time_slice1v')
92 benchutil_set_result ('time_slice2c')
99 benchutil_set_result ('time_slice2r')
101 idx = cumsum (rand (1, m));
102 idx = ceil (idx / idx(end) * m);
109 benchutil_set_result ('time_slice2cv')
116 benchutil_set_result ('time_slice2rv')
118 m = floor (sqrt (n / 6));
119 a = rand (2, m, m, 3);
130 benchutil_set_result ('time_slicenc')
132 m = floor (sqrt (n / 6));
133 a = rand (2, m, 3, m);
144 benchutil_set_result ('time_slicend')
147 a = rand (2, 2, 3, m);
154 benchutil_set_result ('time_slicens')
156 m = floor (sqrt (n));
161 b = a(ones(1, m), :);
164 benchutil_set_result ('time_spreadr')
170 b = a(:, ones(1, m));
173 benchutil_set_result ('time_spreadc')