필터 지우기
필터 지우기

Is there way to suppress the timer?

조회 수: 23 (최근 30일)
Joe
Joe 2013년 5월 5일
댓글: Walter Roberson 2021년 4월 6일
Hello, I am using tic and toc to measure the runtime of MATLAB's sort function for arrays of n lengths. In order to understand how the runtime increases with respect to how large n is I have plotted the runtime vs n. The thing is, it gets kind of troublesome to see MATLAB computing all the runtimes in the command window especially when n gets really large. Is there a way to suppress it like it was an output?

채택된 답변

Cedric
Cedric 2013년 5월 5일
편집: Cedric 2013년 5월 5일
Just use a ; at the end of the line with the toc:
>> tic ; pause(1) ; t = toc ;
Here there is no output for example, and I have to display the content of t to get the value..
>> t
t =
1.0018
I assumed here that you had to store the output of TOC in some variable in order to plot it, and therefore that if there is an output, it's because you don't terminate the line with ;. Now I realize that you might have tried something else where there is no output argument to TOC. In such case, TOC seems to assume that it has to display its time measurement, and it is not something that you can block with ;.
So you have to pick a case with no output from the following:
>> tic ; toc % No output arg => display.
Elapsed time is 0.000001 seconds.
>> tic ; toc ; % Same here indeed.
Elapsed time is 0.000002 seconds.
>> tic ; t = toc % Output arg => no display, but
% the line defines t without ;,
% so t is displayed.
t =
1.0266e-06
>> tic ; t = toc ; % Output arg => no display, and ;
% so t is not displayed.
>> tic ; [~] = toc ; % Same here with ~ so you don't
% have to define a variable name.
  댓글 수: 4
Amir Pasha Zamani
Amir Pasha Zamani 2021년 4월 6일
I have almost the same problem , but not with displaying the time elapssed on the screen, but the computational time of my code.
In fact, I am running a code for 12 hours now. I once stopped it to check the duration of a loop inside it, so that I have an estimation of the time for the whole program.
I activated a tic in the begining and a toc at the end of the loop, and I got what I wanted to know, but now, tic is still on, and it is making my code very slow, after 12 hours.
So I just need to stop counting the time.
Is there a way to do that ? ? ? ? ?
Walter Roberson
Walter Roberson 2021년 4월 6일
If you pause the execution, and then define private/toc.m in the same directory
function toc(varargin)
end
then that might work. But if you get it wrong it might also cause an error, so you would have to be careful in your testing.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Micah Ackerman
Micah Ackerman 2016년 10월 30일
편집: Walter Roberson 2016년 10월 30일
Take a look at the following example and see if it helps. No need to just toc.
tic
%Summation
Dragonfly_data=load('dragonfly.dat');
Sum=0;
x=1;
while x<=100
Sum=Sum+Dragonfly_data(x);
x=x+1;
end
Sum; %Sum is suppressed, because the problem asks for the average.
%Average
Average=Sum/length(Dragonfly_data);
elapsedTime = toc;
fprintf('The average is %-0.3f Hertz.',Average)
fprintf('\nProblem 3 took %-.3f seconds to run.',elapsedTime)
  댓글 수: 1
Kai Xin
Kai Xin 2018년 11월 12일
This works without put the toc at the beginning of the code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by