close all

clear all

clc

a= rand(1e6,1);

b= rand(1e6,1);

c= zeros(size(a));

tic

tstart=tic;

for i=1:length(a)

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

end

t_normal_for=toc(tstart)

tstart=tic;

parfor i=1:length(a)

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

c(i)=a(i)+b(i);

d(i)=c(i)+b(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

e(i)=d(i)+c(i)*a(i)+b(i)/a(i)+b(i)*a(i)+b(i);

end

t_parfor=toc(tstart)

More Ammar Al Abd Alazeez's questions See All
Similar questions and discussions