% Measurement of runtimes for different implementations of matrix products
N = 500;
A = rand(N,N); B = rand(N,N); % Initialize random matrices

res = [];
for n=10:10:N
    An = A(1:n,1:n); Bn = B(1:n,1:n);
    t1 = realmax; for j=1:3, tic; C1 = mlmatprod(An,Bn); t1 = min(toc,t1); end
    t2 = realmax; for j=1:3, tic; C2 = dotmatprod(An,Bn); t2 = min(toc,t2); end
    t3 = realmax; for j=1:3, tic; C3 = loopmatprod(An,Bn); t3 = min(toc,t3); end
    fprintf('%d: %f, %f\n',n,norm(C1-C2), norm(C1-C3));
    res = [res; n, t1, t2, t3];
end

figure; 
plot(res(:,1),res(:,2),'b+',res(:,1),res(:,3),'r.',res(:,1),res(:,4),'m*');
xlabel('{\bf matrix size n}','fontsize',14);
ylabel('{\bf runtime [s]}','fontsize',14);
title('runtime measurements: different ways to implement matrix multiplication');
legend('mlmatprod','dotmatprod','loopmatprod','location','best');
 
print -depsc2 '../../LANMFigures/matprodtiming.eps'; 

figure; 
semilogy(res(:,1),res(:,2),'b+',res(:,1),res(:,3),'r.',res(:,1),res(:,4),'m*');
xlabel('{\bf matrix size n}','fontsize',14);
ylabel('{\bf runtime [s]}','fontsize',14);
title('runtime measurements: different ways to implement matrix multiplication');
legend('mlmatprod','dotmatprod','loopmatprod','location','best');
 
print -depsc2 '../../LANMFigures/matprodtiminglog.eps'; 

