blas_test.m function test vn vn [5,50,200,500] if 0 et =zeros(1,4) et2 et2 zeros(1,4) idn idn 1 B B rand(n) C C rand(n) tic tic for for i i 1:10 C=matmult(A,B) exec_times_b exec_times_b XScale XScale for for k k 1:size(A,2) sum=sum+A(i,k)*B(k,j) end end et (idn) et idn end end et2 (idn) et2 idn end save blas_test else load blas_test end end save blas_test else load blas_test end itload ('../blas_test.it') figure plot(vn itload '../blas_test.it' end save blas_test else load blas_test end et hold on end save blas_test else load blas_test end et hold on plot (vn, et2,'r') plot vn et2 'r' plot (vn, exec_times,'--') plot(vn plot vn exec_times '--' 'For cycle vs.BLAS' 'For cycle vs. BLAS' title () title ylabel ('execution time') ylabel 'execution time' xlabel ('matrix size') xlabel 'matrix size' set (gca,'YScale','log') set(gca set gca 'YScale' 'log' log set (gcf,'PaperPositionMode','auto') set gcf 'PaperPositionMode' 'auto' legend ('matlab for','matlab blas','IT++for','IT++blas','C array') function C legend 'matlab for' 'matlab blas' 'IT++for' 'IT++blas' 'C array' end end C (i, j) C i j functiontest vn= if0 et=zeros(1,4); et2=zeros(1,4); idn=1; vn= forn=vn A=rand(n);B=rand(n);C=rand(n); tic; fori=1:10 C=matmult(A,B); end et(idn)=toc; tic; fori=1:10 C=A*B; end et2(idn)=toc; idn=idn+1; end saveblas_test else loadblas_test end itload('../blas_test.it') figure plot(vn,et) holdon plot(vn,et2,'r'); plot(vn,exec_times,'--') plot(vn,exec_times_b,'r--') plot(vn,exec_times_c,'g--') title('Forcyclevs.BLAS'); ylabel('executiontime'); xlabel('matrixsize'); set(gca,'YScale','log') set(gca,'XScale','log') set(gcf,'PaperPositionMode','auto'); legend('matlabfor','matlabblas','IT++for','IT++blas','Carray') functionC=matmult(A,B) fori=1:size(A,1) forj=1:size(A,2) sum=0; fork=1:size(A,2) sum=sum+A(i,k)*B(k,j); end C(i,j)=sum; end end