[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
3D versus 2D Indexing and the Speed Thereof
From: |
John W. Eaton |
Subject: |
3D versus 2D Indexing and the Speed Thereof |
Date: |
Tue, 21 Nov 2006 02:53:03 -0500 |
On 20-Nov-2006, Luis Ortiz wrote:
| The first snippet of code he gave me to consider was:
| x=zeros(100,50,100);
| tic;
| for i = 1:100
| z = x(:,:,i);
| end
| toc
|
| The second snippet of code he gave me to consider was:
| x=zeros(5000,100);
| tic;
| for i = 1:100
| z = x(:,i);
| end
| toc
|
| Now the 2D form is about 22 times faster than the 3D form, even though
| the amount of data being slung about is the same.
The two functions to start with are Array<T>::index2 and
Array<T>::indexN in the file liboctave/Array.h. The 2-d function is
the original, from the olden times when Octave only had 2-d arrays.
The N-d version should be able to handle 2-d arrays too, but as you
noticed it is much slower so we kept the strictly 2-d version around.
It would be better to have just one function that handles all arrays,
but clearly I don't know how to make it as efficient as the
specialized 2-d case.
This reminds me that I have an idea about a new logo for Octave. It
should be a dancing bear because the amazing thing about a dancing
bear is not how well it dances. The amazing thing is that it dances
at all.
jwe