Script-Based Performance Test Function-Based Performance Test
vectorSize = 1e7;%% Ones Function
x = ones(1,vectorSize);%% Indexing With Variable
id = 1:vectorSize;
x(id) = 1;%% Indexing On LHS
x(1:vectorSize) = 1;%% For Loop
for i=1:vectorSize
x(i) = 1;
endfunction tests = preallocationTest
tests = functiontests(localfunctions);
endfunction testOnes(testCase)
vectorSize = getSize();
x = ones(1,vectorSize());
endfunction testIndexingWithVariable(testCase)
vectorSize = getSize();
id = 1:vectorSize;
x(id) = 1;
endfunction testIndexingOnLHS(testCase)
vectorSize = getSize();
x(1:vectorSize) = 1;
endfunction testForLoop(testCase)
vectorSize = getSize();
for i=1:vectorSize
x(i) = 1;
end
endfunction vectorSize = getSize()
vectorSize = 1e7;
endRun Performance TestRun the performance test using runperf.results = runperf('preallocationTest.m')Running preallocationTest
.......... .......... .......... ..
Done preallocationTest
__________results =33 Unit Testing