N = 1e2;

f = zeros(N,1);
for i=1:N
  r = rand(5000,1);
  s = diag(r);
  tic;
  z = nnz(s);
  f(i)=toc;
endfor

sum(f)