I am working on the code below in Matlab. When you make bigger the parameters it takes too much time to finish run. Then I want to optimize the code to make it run faster. I didnt take any algorith optimization course yet. However I have changed some parts of it. The code is faster now but, it is not enough.
Do you have an idea guys to make it faster? Preallocation, initializing before-later, whatever..
rand('state', sum(100*clock));
runs=10000;
bw=20000; ttimeout=303/bw; ts=20/bw;
sift_times=[];sift_tcolls=[];sift_tcws=[];
range_n=5;
for n = range_n
sift_collisions=[];
uniform_collisions=[];
for w=3:63
uniform_collision=0;
sift_collision=0;
for i=1:runs
%Sift Dist:
chosen_slots = sift_assign_slots(w,n);
[slots,nodes] = sort(chosen_slots);
if (slots(1)==slots(2))
sift_collision = sift_collision + 1;
end
%Uniform Dist:
chosen_slots = ceil(w*rand(n,1));
[slots,nodes] = sort(chosen_slots);
if (slots(1)==slots(2))
uniform_collision = uniform_collision + 1;
end
end
sift_collisions (w-2) = sift_collision ;
uniform_collisions(w-2) = uniform_collision ;
end
end