1function sstest2
2%SSTEST2 exhaustive performance test for SSMULT.  Requires ssget.
3% ssget is available at http://www.suitesparse.com
4%
5% Example
6%   sstest2
7%
8% See also ssmult, ssmultsym, ssmult_install, sstest, ssget, mtimes.
9
10% Copyright 2007-2009, Timothy A. Davis, http://www.suitesparse.com
11
12help sstest2
13
14try
15    index = ssget ;
16catch
17    fprintf ('\nsstest2 requires ssget.\n') ;
18    fprintf ('see http://www.suitesparse.com\n') ;
19    return ;
20end
21[ignore, f] = sort (index.nnz) ;                                            %#ok
22
23nmat = length (f) ;
24TM = zeros (nmat, 4) ;
25T1 = zeros (nmat, 4) ;
26tlim = 0.01 ;
27
28tmin = 1 ;
29tmax = 0 ;
30
31check = 1 ;
32rand ('state', 0)
33
34for k = 1:nmat
35
36    Prob = ssget (f (k), index) ;
37    A = Prob.A ;
38    clear Prob
39
40    for kind = 1:4
41
42        try
43            if (~isreal (A))
44                A = spones (A) ;
45            end
46            B = A' ;
47
48            if (kind == 2)
49                A = sprand (A) + 1i*sprand(A) ;
50                B = sprand (B) ;
51            elseif (kind == 3)
52                A = sprand (A) ;
53                B = sprand (B) + 1i*sprand(B) ;
54            elseif (kind == 4)
55                A = sprand (A) + 1i*sprand(A) ;
56                B = sprand (B) + 1i*sprand(B) ;
57            end
58
59            C = A*B     ; % warmup
60
61            if (check)
62
63                D = ssmult (A,B) ;
64                err = norm (C-D,1) ;
65                if (err > 0)
66                    fprintf ('err: %g\n', err) ;
67                    error ('!')
68                end
69                clear D
70
71            else
72
73                % warmup, for accurate timings
74                C = ssmult (A,B) ;                                          %#ok
75                clear C
76
77            end
78
79            tr = 0 ;
80            tm = 0 ;
81            tic
82            while (tm < tlim)
83                C = A*B ;                                                   %#ok
84                clear C
85                tr = tr + 1 ;
86                tm = toc ;
87            end
88            tm = tm / tr ;
89
90            tr = 0 ;
91            t1 = 0 ;
92            tic
93            while (t1 < tlim)
94                C = ssmult (A,B) ;                                          %#ok
95                clear C
96                tr = tr + 1 ;
97                t1 = toc ;
98            end
99            t1 = t1 / tr ;
100
101            fprintf ('%4d: %4d ', k, f(k)) ;
102            fprintf (...
103            'MATLAB %12.6f SSMULT %12.6f  speedup %12.3f', ....
104                tm, t1, tm / t1) ;
105
106            if (tm < t1)
107                fprintf (' ****') ;
108            end
109            fprintf ('\n') ;
110
111            TM (k,kind) = tm ;
112            T1 (k,kind) = t1 ;
113
114            tmin = min (tmin, tm) ;
115            tmax = max (tmax, tm) ;
116
117        catch me
118            disp (me.message)
119            TM (k,kind) = 1 ;
120            T1 (k,kind) = 1 ;
121        end
122
123    end
124
125    for kind = 1:4
126
127        subplot (2,4,kind) ;
128        r = TM (1:k,kind) ./ T1 (1:k,kind) ;
129        rmin = min (r) ;
130        rmax = max (r) ;
131        loglog (TM (1:k,kind), r, 'o', ...
132            [tmin tmax], [1 1], 'r-', ...
133            [tmin tmax], [1.1 1.1], 'r-', ...
134            [tmin tmax], [1/1.1 1/1.1], 'r-', ...
135            [tmin tmax], [2 2], 'g-', ...
136            [tmin tmax], [1.5 1.5], 'g-', ...
137            [tmin tmax], [1/1.5 1/1.5], 'g-', ...
138            [tmin tmax], [.5 .5], 'g-' );
139        if (k > 2)
140            axis ([tmin tmax rmin rmax]) ;
141        end
142        xlabel ('MATLAB time') ;
143        ylabel ('MATLAB/SM time') ;
144        if (kind == 1)
145            title ('real*real') ;
146        elseif (kind == 2)
147            title ('complex*real') ;
148        elseif (kind == 3)
149            title ('real*complex') ;
150        elseif (kind == 4)
151            title ('complex*complex') ;
152        end
153
154    end
155
156    drawnow
157
158    clear A B C
159    save sstest2_results.mat TM T1 f
160    diary off
161    diary on
162
163end
164
165