From: Marios Karaoulis on
Hi, which of the following is faster.
I have two options.


for i=1:100
for j=1 to 20.000
Calculate lala 8X8 matrix
use values of lala matrix
end
end

or calculate once lala and store it as a 3d matrix like
lala(8,8,20000) and
for i=100
use values from lala matrix
end

I am doing some testes and I can't decide if it is better to have free
memory or reduce calculations
From: Walter Roberson on
Marios Karaoulis wrote:
> Hi, which of the following is faster.
> I have two options.
>

> for i=1:100
> for j=1 to 20.000
> Calculate lala 8X8 matrix
> use values of lala matrix
> end
> end

> or calculate once lala and store it as a 3d matrix like
> lala(8,8,20000) and
> for i=100
> use values from lala matrix
> end

> I am doing some testes and I can't decide if it is better to have free
> memory or reduce calculations

It depends on the amount of vectorization you can get in building the 3D
matrix. If you can vectorize, then the 3D construction will probably
execute more quickly; if you end up building lala in a loop then the 3D
version will probably not be faster.

Generally speaking, having free memory doesn't do you any good, not
unless doing so prevents you from swapping to disk. The computations are
not going to run any faster if you have 10 bytes or 10 gigabytes free.
(Actually, that's not completely true. Historically, memory allocation
algorithms got exponentially slower once more than 85% of the memory is
allocated, as it starts taking longer to find a free block of the
appropriate size.)
From: James Tursa on
Marios Karaoulis <marios.karaoulis(a)gmail.com> wrote in message <d2e2ff8c-721e-4525-8354-538cf84211d8(a)z13g2000prh.googlegroups.com>...
> Hi, which of the following is faster.
> I have two options.
>
>
> for i=1:100
> for j=1 to 20.000
> Calculate lala 8X8 matrix
> use values of lala matrix
> end
> end
>
> or calculate once lala and store it as a 3d matrix like
> lala(8,8,20000) and
> for i=100
> use values from lala matrix
> end
>
> I am doing some testes and I can't decide if it is better to have free
> memory or reduce calculations

The answer will likely depend on how you are using the lala matrix in your downstream code and whether or not you can vectorize the downstream calculations. Without knowing anything more about your downstream use, I would in general advise going the lala(8,8,20000) route.

James Tursa
From: Marios Karaoulis on
I have a strange filling that when i get values from a 3d matrix, is
somehow slow, Am I wrong?
From: Steven Lord on

"Marios Karaoulis" <marios.karaoulis(a)gmail.com> wrote in message
news:765a997a-a340-4aa2-8bd7-0e18cd24b636(a)23g2000pre.googlegroups.com...
>I have a strange filling that when i get values from a 3d matrix, is
> somehow slow, Am I wrong?

That depends on the technique you used to fill the array. [Matrices are
2-D, arrays can be of any number of dimensions.]

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com