Computer programs (code) can be:
Sometimes this is important, however often it is not. Typically, readability is more important.
Can be assessed directly by timing how long code takes to run. Time will vary even on the same machine, as it depends on the hardware and the load on the machine. The inbuilt tic...toc
function is used to measure this, and it prints the time taken of the lines of code in-between the function. e.g.
function sumOfIntegers(N)
% ...
tic
for j = 1:N
total = total + a(j);
end
toc
% ...
>> sumOfIntegers(1000000)
Elapsed time is 0.014182 seconds.
...
The rest of this chapter will be completed soon