% Comparaison de la rapidité de plusieurs méthodes 
% de calcul de la factorielle grace a tic & toc.

clear; nmin=2; nmax=150; N=[nmin:nmax];
for n=N,
 m=n-nmin+1;
 tic; fact(n); T(m,1)=toc;
 tic; f=nmin; for i=nmin+1:n; f=f*i; end; T(m,2)=toc;
 tic; cumprod(nmin:n); T(m,3)=toc;
 tic; gamma(n-1); T(m,4)=toc;
end
clf; hold on; title('Calcul de la factorielle');
plot(N,T(:,1),N,T(:,2),N,T(:,3),N,T(:,4));
xlabel('n'); ylabel('Temps');
legend('Recursif','Boucle','cumprod','gamma built-in',2);