]> Creatis software - CreaPhase.git/blob - octave_packages/benchmark-1.1.1/benchmark_dtmm.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / benchmark-1.1.1 / benchmark_dtmm.m
1 % Copyright (C) 2008  Jaroslav Hajek <highegg@gmail.com>
2
3 % This file is part of OctaveForge.
4
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.
9
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.
14
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/>.
18
19
20 % function benchmark_dtmm (m, n, nvec)
21 % description:
22 % Dense transposed matrix-matrix and matrix-vector multiplication benchmark.
23 % This is to test the "compound operators" feature introduced in Octave.
24 %
25 % arguments:
26 % m = row dimension of matrices
27 % n = col dimension of matrices
28 % nvec = number of vector op repeats
29 %
30 % results:
31 % time_tmm = Time for A'*B (A,B m-by-n matrices)
32 % time_smm = Time for A'*A
33 % time_mtm = Time for A*B' (A,B n-by-m matrices)
34 % time_msm = Time for A*A'
35 % time_tmv = Time for A'*v nvec-times (A m-by-n matrix)
36 % ratio_tmv = Ratio to precomputed transpose time
37 % time_mtv = Time for v*A' nvec-times (A m-by-n matrix)
38 % ratio_mtv = Ratio to precomputed transpose time
39 %
40
41 function results = benchmark_dtmm (m, n, nvec)
42
43   benchutil_default_arg ('m', 40192);
44   benchutil_default_arg ('n', 150);
45   benchutil_default_arg ('nvec', 100);
46
47   benchutil_initialize (mfilename)
48
49   A = rand (m, n);
50   B = rand (m, n);
51
52   tic; C = A'*B; time_tmm = toc;
53   benchutil_set_result ('time_tmm')
54
55   tic; C = A'*A; time_smm = toc;
56   benchutil_set_result ('time_smm')
57
58   A = A';
59   B = B';
60
61   tic; C = A*B'; time_mtm = toc;
62   benchutil_set_result ('time_mtm')
63
64   tic; C = A*A'; time_msm = toc;
65   benchutil_set_result ('time_msm')
66
67   A = A';
68
69   v = rand (m, 1);
70   tic;
71   for i=1:nvec
72     c = A'*v;
73   end
74   time_tmv = toc;
75   benchutil_set_result ('time_tmv')
76
77   B = A';
78   tic;
79   for i=1:nvec
80     c = B*v;
81   end
82   ratio_tmv = time_tmv / toc;
83   benchutil_set_result ('ratio_tmv')
84
85   v = rand (1, n);
86   tic;
87   for i=1:nvec
88     c = v*A';
89   end
90   time_mtv = toc;
91   benchutil_set_result ('time_mtv')
92
93   tic;
94   for i=1:nvec
95     c = v*B;
96   end
97   ratio_mtv = time_mtv / toc;
98   benchutil_set_result ('ratio_mtv')
99