Thank you for your replies, but i can not use tic() #my code toc() because all i want is a CPU time, and i can't use @time myFunction because it's in the middle of the function, see the matlab code below. I do t0=cputime; on the first line of my function and t = [t cputime-t0]; on the sixth line from the bottom.
Sadly i can not do the same thing in Julia, although here https://github.com/schmrlng/CPUTime.jl they are many macros concerning CPU time. function [H,e,t]=func(A,H,maxiter,timelimit) t0 = cputime; [n,r] = size(H); e = []; t = []; iter = 1; x = zeros(1,4); if nargin < 3, maxiter = 100; end if nargin < 4, timelimit = 60; end HHt = H*H'; scaling = sum(sum(A.*HHt))/sum(sum(HHt.*HHt)); H = sqrt(scaling)*H; while iter <= maxiter && cputime-t0 <= timelimit R = A-H*H'; for k=1:r R = R+H(:,k)*H(:,k)'; dR = diag(R); HtH = H(:,k)'*H(:,k); for i=1:n HtH = HtH-H(i,k)^2 ; a = HtH-dR(i); b = -(H(:,k)'*R(:,i) - H(i,k)*dR(i)); Delta = 4*a^3+27*(b)^2; d = 0.5*(-b+sqrt(Delta/27)); if Delta <= 0 r3 = 2*(abs(d)^(1/3)); th3 = angle(d)/3; x(2) = r3*cos(th3); x(3) = r3*cos(th3+(2*pi/3)); x(4) = r3*cos(th3+(4*pi/3)); x = x(x>=0); [~,ind] = min(x.^4/4+a*x.^2/2 + b*x); H(i,k) = x(ind); HtH = HtH + H(i,k)^2; else z = sign(d)*(abs(d))^(1/3); val = z-a/(3*z); if val.^4/4+a*val.^2/2 + b*val<0 && val >= 0 HtH = HtH + val^2; H(i,k) = val; else H(i,k) = 0; end end end R=R-H(:,k)*H(:,k)'; end if nargout >=2 t = [t cputime-t0]; e = [e 0.5*norm(A-H*H','fro')^2]; end iter = iter + 1; end end On Wednesday, 3 February 2016 21:28:28 UTC+1, Lytu wrote: > > Hello Julia users, > > Can someone tell me what's the equivalent of matlab elapsed cputime in > Julia > > For example i Matlab, we can do this: > > t = cputime; > x=4; > > iter = 1; > > z = ones(1,4); > > y=x*2*z; > > e = cputime-t > > > But in Julia i don't seem to find how to do this. I thought i can use > > t=time() > > x=4; > > iter = 1; > > z = ones(1,4); > > y=x*2*z; > > e=time()-t > > > But time() in Julia is not the elapsed CPU time, it's a wall clock time. > > > Can someone help me? > > > Thank you > >