Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Again terrible problem with profiler

1 visualizzazione (ultimi 30 giorni)
Michal
Michal il 20 Ott 2017
Commentato: Michal il 20 Ott 2017
I am again facing to terrible profiler problem (under Matlab R2017b). I have two codes doing exactly identical computing (counting of permutation cycles):
Code1:
function count = PermCyclesCount(p)
[nR,N] = size(p);
count = zeros(nR,1);
for j = 1:nR
i=0;
count(j) = 0;
while i<N
i=i+1;
if p(j,i)>0
flag=0; % flag is just to trick the computer into entering the while loop
first=i;
while (first ~=i) || (flag==0)
flag=1;
r=first;
first=p(j,first);
p(j,r)=0; % The entries in the cycle are changed to zero to indicate that they have been `used'
end
count(j) = count(j) + 1;
end
end
end
end
And Code2:
function count2 = PermCyclesCount_(p)
nR = size(p,1) ;
count2 = zeros(nR,1) ;
tf = ~isnan(p) ;
for j = 1:nR
r1 = find(tf(j,:), 1 ,'first') ; % find the first cycle
while ~isempty(r1) % is there a cycle
count2(j) = count2(j) + 1 ;
while tf(j,r1)
tf(j,r1) = false ;
r2 = p(j,r1) ;
r1 = r2 ;
end
r1 = find(tf(j,:),1,'first') ; % find the next cycle
end
end
end
Testing data are simply created by command:
[~,perms] = sort(rand(1000,60),2);
For "profile off" I have got the following results:
tic;c= PermCyclesCount(perms);toc
Elapsed time is 0.193138 seconds.
tic;c_= PermCyclesCount_(perms);toc
Elapsed time is 0.627378 seconds.
For "profile on" I have got the following results:
tic;c= PermCyclesCount(perms);toc
Elapsed time is 1.927052 seconds.
tic;c_= PermCyclesCount_(perms);toc
Elapsed time is 1.524331 seconds.
So, the profiler produce completely distorted results, which has nothing to do with real performance on "profile off" regime!!!
  2 Commenti
Michal
Michal il 20 Ott 2017
No, not at all!!! In this post I am reporting problem with profiler. Do you see the difference?

Risposte (0)

Tag

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by