MATLAB: Are Infs still faster than NaNs

infnanspeed

Years ago, I was advised that the processing of Inf elements was much faster than the processing of NaN elements, and was advised to use Infs instead of NaNs unless there was a compelling reason. When I replaced NaNs with Infs, I did indeed find that Infs crunched much faster. In recent days, though (R2013), I'm finding that the playing field is pretty even among Infs, NaNs, and finite array elements, e.g.,
>> A=nan(3e3); tic;fft2(A);toc
Elapsed time is 0.192480 seconds.
>> A=inf(3e3); tic;fft2(A);toc
Elapsed time is 0.200329 seconds.
>> A=rand(3e3); tic;fft2(A);toc
Elapsed time is 0.211940 seconds.
Was I hallucinating back then, or has there been an improvement in the hardware/software that handles NaNs and Infs?

Best Answer

Hmmm, possibly a false alarm. In the tests below, minimization operations involving NaNs are still noticeably slower,
n=1e4;k=1e4;
A=rand(n,k);b=randi(k,n,1);
idx=bsxfun(@lt,b,(1:k));
A(idx)=nan;
tic
c=min(A,[],2);
toc
%Elapsed time is 0.348245 seconds.
A(idx)=inf;
tic
c=min(A,[],2);
toc
%Elapsed time is 0.126220 seconds.
Still, I seem to remember that a lot of other operations were slower, too.