Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Again terrible problem with profiler

조회 수: 1 (최근 30일)
Michal
Michal 2017년 10월 20일
댓글: Michal 2017년 10월 20일
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
Michal
Michal 2017년 10월 20일
No, not at all!!! In this post I am reporting problem with profiler. Do you see the difference?

답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by