dim=1e3*2.^(1:6); %test dimensions
cpu=zeros(length(dim),1); %for store CPU times
for k=1:length(dim) 
    tic %start timing
    x=rand(dim(k),1); %random vector
    y=BBsort(x); %sorting algorithm
    cpu(k)=toc; %measure CPU time in seconds
end
loglog(dim,cpu,'-o') %plot the time growth, in log-log scale
xlabel('Dimension of vector')
ylabel('CPU time')
title('Bubble sorting: CPU time vs Dimension')

p=polyfit(log(dim'),log(cpu),1); %fit the line, log values
slope=p(1) %extract the slope, should be close to 2