I am writing programs that are very speed sensitive. Why are there timing differences in the computation of the following equivalent matrix multiplication scenarios? The scenarios are:
1. C - C*A*A'2. C - C * B % where B is pre-computed as A*A'
3. C * (I - D) % where D is pre-computed as A * B
In the following example:
>> N=4;>> M=10^N;>> A=randn(200,6);>> B=A*A';>> C=randn((16*50),200);>> D=eye(200)-B;>> E=randn((16*50),200);>> F=randn((16*50),200);>> G=randn((16*50),200);>> tic;for(ii=1:M),E=C-C*A*A';end;toc/M,tic;for(ii=1:M),F=C-C*B;end;toc/M,tic;for(ii=1:M),G=C*D;end;toc/M
The timing results are:
0.000520.000980.00085
As you notice, the time required for the second and third scenarios are approximately twice as that by the first scenario.
Best Answer