Hello,
I am trying to evaluate how long does it take i) for one CPU core to perform a multiplication of two real numbers, ii) to read/write one number to RAM. Numbers are doubles. As I have to find more than one unknown I am planning to run several simulations (schematically):
tic
2*2;
toc ; data 2. Just multiplication
tic
z(ii) = 2*2;
toc ; data 3. Multiplication and one writing
tic
x(ii)*y(ii);
toc ; data 4. Multiplication and two reading
tic
z(ii) = x(ii)*y(ii);
toc ; data 5. Multiplication, two reading and one writing
Surprisingly I get very strange data  z(ii)=2*2 is executed faster than 2*2 and z(ii)=x(ii)*y(ii) faster than x(ii)*y(ii)!
What I do exactly:
1) Set affinity of the MATLAB process to one CPU core. I do it via Task Manager.
2) Run the following code:
clc;
clear;
W = 32;
K = 10^5;
tt = zeros(5,W)
for jj=1:W
% jj
X = randn(K*jj,1);
Y = randn(K*jj,1);
Z = zeros(K*jj,1);
fprintf('Data size =%d \n',K*jj);
tStart = tic;
for ii=1:K*jj
% 2*2;
end;
tStop = toc(tStart);
tt(1,jj)=tStop;
tStart = tic;
for ii=1:K*jj
2*2;
end;
tStop = toc(tStart);
tt(2,jj)=tStop;
tStart = tic;
for ii=1:K*jj
Z(ii)=2*2;
end;
tStop = toc(tStart);
tt(3,jj)=tStop;
tStart = tic;
for ii=1:K*jj
X(ii)*Y(ii);
end;
tStop = toc(tStart);
tt(4,jj)=tStop;
tStart = tic;
for ii=1:K*jj
Z(ii) = X(ii)*Y(ii);
end;
tStop = toc(tStart);
tt(5,jj)=tStop;
end;
figure;
ColorOrd = get(gca,'ColorOrder');
for ii=1:5
plot(1*K:1*K:K*W, tt(ii,:), 'Linewidth', 2, 'Color', ColorOrd(ii,:)), hold on;
end;
grid on;
% set(gca,'XTick', 1*K:1*K:K*W );
xlabel('Vectors'' size');
ylabel('Time');
hleg = legend('show');
set(hleg,'Location','NorthWest');
I am on Lenovo ThinkPad W510, Intel i7 vPro with 8 cores i7 Q820, 16 GB RAM, Windows 7 Pro and MATLAB R2010b.
So, my question is what is really happens between CPU and RAM when I run code 2*2, z(ii)=2*2, x(ii)*y(ii) and z(ii)=x(ii)*y(ii)?
Is there is any other ways to evaluate the multiplication and read/write time?
Thank you in advance.
