% OperationsTime.m
% Speeds of addition, subtraction, multiplication, & division in MATLAB.
% Result: No noticable difference in the speeds of 
% addition, subtraction, and multiplication.
% However division is about 50% slower.

% K. Ming Leung, 02/20/04
clear all;
format short;
N = 100000;
repeat = 100;

a = [ (1:N)' rand(N,1) ];             % Integer | floating point data
b = [ (1:N)' rand(N,1) ];             % Integer | floating point data

a = [ rand(N,1) (1:N)'];             % floating point | Integer data
b = [ rand(N,1) (1:N)'];             % floating point | Integer data


for m = 1:2
n = 1;

% Addition
t0 = clock;
for i=1:repeat
    result = a+b;
end
time = etime(clock,t0);
RESULT(n,m) = (time);

n = n+1;

% Subtraction
t0 = clock;
for i = 1:repeat
    subtraction = a(:,m)-b(:,m);
end
time = etime(clock,t0);
RESULT(n,m) = (time);
n = n+1;

% Multiplication 
t0 = clock;
for i = 1:repeat
    result = a(:,m).*b(:,m);
end
time = etime(clock,t0);
RESULT(n,m) = (time);
n = n+1;

% Division
t0 = clock;
for i = 1:repeat
    result = a(:,m)./b(:,m);
end
time = etime(clock,t0);
RESULT(n,m) = (time);
end

disp('   int      float');
disp(RESULT);