% compare_mult_speed_3.m
% C Bishop 1-23-2023
% compare code for sparse martrix multiplication
% and plot results

time1=[];time2=[];time3=[];
iter=[2:7];
for t=iter
n=2^t;
A=sparse(n,n);
B=sparse(n,n);
for k=1:n
j=randi(n);
k=randi(n);
A(j,k)=rand;
j=randi(n);
k=randi(n);
B(j,k)=rand;
end % for k
tic;
C=A*B;
time1=[time1,toc];
tic;
C=full(A)*full(B);
time2=[time2,toc];
tic;
C=zeros(n);
for k=1:n
for j=1:n
for m=1:n
C(k,j) =C(k,j)+A(k,m)*B(m,j);
end % for m
end % for j
end % for k
t
time3=[time3,toc];
[time1;time2;time3]
end % for t
figure; hold on; grid on;
plot(iter,time1)
plot(iter,time2)
plot(iter,time3)
legend({'sparse','full','loops'})

figure; hold on; grid on;
plot(iter,log(time1))
plot(iter,log(time2))
plot(iter,log(time3))
legend({'sparse','full','loops'})