Originally Posted by

**MK27**
Dynamic arrays in the higher level interpreted languages -- perl, python, etc, where an array is an array, it's dynamic, it's managed for you, and that's it -- are allocated in power of two blocks. I've seen plenty of tests demonstrating these things will execute as fast as a compiled C/C++ equivalent, tho of course many many people are still in howling fantoid denial about this.

Maximizing MATLAB Performance (Programming and Data Types) - straight from MathWorks

Code:

% test1.m
clear
tic
for x=1:100000
y(x)=sin(x);
end
toc

Code:

% test2.m, same as test1.m but with array preallocation
clear
tic
y=zeros(1,100000); % equivalent of calloc()
for x=1:100000
y(x)=sin(x);
end
toc

Code:

% test3.m, vectorized, just for reference
clear
tic
x=1:100000;
y=sin(x);
toc

Code:

octave:1> test1
Elapsed time is 6.54621 seconds.
octave:2> test1
Elapsed time is 6.5474 seconds.
octave:3> test1
Elapsed time is 6.57896 seconds.
octave:4> test2
Elapsed time is 6.15879 seconds.
octave:5> test2
Elapsed time is 6.16064 seconds.
octave:6> test2
Elapsed time is 6.12372 seconds.
octave:7> test3
Elapsed time is 0.0375661 seconds.
octave:8> test3
Elapsed time is 0.0275859 seconds.
octave:9> test3
Elapsed time is 0.039516 seconds.
octave:10>