matlab efficiency - slicing vs assignment
<p>I am curious, is there a large speed difference in MATLAB between computing with a slicing of a matrix vs. assigning the slicing to another variable, then computing with the variable?</p>

<p>I.e. the difference between the following:</p>

<pre><code>A = randn(1000,1000);
x = randn(500,1);
y = A(:,1:500)*x;
</code></pre>

<p>and</p>

<pre><code>A = randn(1000,1000);
x = randn(500,1);

Ahat = A(:,1:500);
y = Ahat*x;
</code></pre>

<p>I usually use the second for clarity, but is the latter more inefficient memory / computation wise because extra memory is being used in creating Ahat?</p>

<p>And does the answer change if I have to multiple by many x_i vectors? In that case, is it better to reassign to a new variable because (possibly) memory access for slicing is slower?</p>