how to find the execution time of a matlab program.

3 Kommentare

Paulo Abelha
Paulo Abelha am 17 Sep. 2016
Hi,
I've coded a function that might help you:
https://uk.mathworks.com/matlabcentral/fileexchange/59187-displayestimatedtimeofloop--tot-toc--curr-ix--tot-iter--
Ijaz Ahmad
Ijaz Ahmad am 21 Apr. 2021
The best to do is to use the "Run and Time" in the "Editor" menu. It shows a complete summary of every function that has been called and the time it has taken.
Walter Roberson
Walter Roberson am 21 Apr. 2021
Run and Time changes the execution time, sometimes a fair amount.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Namrata
Namrata am 18 Feb. 2011

11 Stimmen

execution time can be found by tic-toc command.place tic; before the first line of code and toc; after the last line of the code
e.g.
tic;
MATLAB code
toc;

5 Kommentare

Masoud Afrakhteh
Masoud Afrakhteh am 14 Jun. 2013
Wow... Thanks !!!
mahesh vuppala
mahesh vuppala am 15 Mär. 2015
very thanks to you
Shoriful Islam Shuvo
Shoriful Islam Shuvo am 23 Jul. 2018
Is there any limitation of tic toc command?
Dario gms
Dario gms am 16 Nov. 2020
The first time I read this i though it was a bad joke, nvm thank you
Bin Qi
Bin Qi am 3 Feb. 2021
It is a legit answer. Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Iain
Iain am 14 Jun. 2013

1 Stimme

Its more powerful to use "now" to get the current time than tic & toc, but it takes a bit more effort.

2 Kommentare

Alexander Andreychenko
Alexander Andreychenko am 5 Apr. 2016
Are you aware of anything that allows folding of tic/toc ? I found that there are undocumented options for tic and toc but what I exactly want is the following:
tic
% doing something large
tic
function_1();
functionTime_1 = toc;
tic
function_2();
functionTime_2 = toc;
wholeTime = toc;
Currently, in this case I see functionTime_1 and functionTime_2 but I don't see the way to get wholeTime.
Walter Roberson
Walter Roberson am 5 Apr. 2016
now1 = tic();
function_1();
functionTime_1 = toc(now1);
now2 = tic();
function_2();
functionTime_2 = toc(now2);
wholeTime = toc(now1);

Melden Sie sich an, um zu kommentieren.

Mohd Sapiee
Mohd Sapiee am 4 Dez. 2018

1 Stimme

Also it is very useful to know the time taken or elapsed in Matlab is reading data from an Excel file, especially for very large number of Excel cells.
tic;
xlsread( );
toc;
Oleg Komarov
Oleg Komarov am 18 Feb. 2011

0 Stimmen

Also, you can use the profiler
Oleg

1 Kommentar

Anuj Patil
Anuj Patil am 6 Jun. 2018
Profiler will give compile+execution time,so not useful in most applications. timeit seems a good option.
Also you can manually use 'clock' function.

Melden Sie sich an, um zu kommentieren.

Royi Avital
Royi Avital am 18 Feb. 2011

0 Stimmen

I really like using TimeIt.

Kategorien

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by