Indexing speed of arrays with different index data types
Here is a simple test to prove that integers arefaster than singles or doubles for indexing matlab arrays.
%% test indexing function untitled function test(type) % eg : int32(floor(rand(1,100)*100+1)) k = eval(sprintf('%s(floor(rand(1,100)*100 + 1))', type)); x = rand(1,100); tic for i = 1:1e5 y = x(k); end toc fprintf('%s\n', type); end test('int32'); test('uint32'); test('single'); test('double'); end
The results are
Elapsed time is 0.194030 seconds. int32 Elapsed time is 0.195234 seconds. uint32 Elapsed time is 0.413456 seconds. single Elapsed time is 0.804347 seconds. double
Thus indexing with integers is definately faster.