Compute execution time without printing statement?
Show older comments
I am wondering if it is possible to compute the execution time using tic and toc statement but eliminating printing time?
I have a big program ... and it has a lot of printing statements in the middle ...
Is it possible to count the time without the time consumed by printing? or should I stop each printing statement one by one?
2 Comments
James Tursa
on 4 Sep 2019
Do you mean you have lots of disp( ) or fprintf( ) etc. statements, but want to somehow not count them in the timing results?
Seereen
on 4 Sep 2019
Answers (1)
Fabio Freschi
on 4 Sep 2019
Edited: Fabio Freschi
on 4 Sep 2019
You can just save the value in a variable
timerValue = tic;
% something very useful to do
tstop = toc(timerValue);
4 Comments
Fabio Freschi
on 4 Sep 2019
Edited: Fabio Freschi
on 4 Sep 2019
The use of timerValue allows you to use different tic/toc statements without confusion or miscalculation
Seereen
on 4 Sep 2019
Fabio Freschi
on 4 Sep 2019
ok, sorry...
Count the time for printf wit tic/toc like I said and subctract the value from the time of computation
Rik
on 4 Sep 2019
You could also try to shadow the fprintf function, but that is a dangerous business.
Categories
Find more on Scope Variables and Generate Names in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!