I am working with loops.I am using tic toc to check the time. I get different time when i run the same loop. The time is close to each other eg. 98.2 and 97.7. secondly when i reduce the size of the loop to half, i expect the time to change in half but it doesn't. Can anyone explain me how tic toc actually works? Thanks.
tic
for i=1:124
for j=1:10
for k=1:11
end
end
end
toc
Secondly i tried to use tic toc inside the loop as shown below. Will it return total time? I get a number but i cant verify if it actually is the total.
for i=1:124
tic
for j=1:10
for k=1:11
end
end
toc
end
tic
andtoc
just measure the elapsed time in seconds. MATLAB has now JIT meaning that the actual time to compute cannot be estimated correctly. Matlab has (at least in this context) no real-time computation, so you basically always have different elapsed time for the same code.Read this here, its nicely explained, hopefully it helps: http://www.matlabtips.com/matlab-is-no-longer-slow-at-for-loops/