edgarmtze
edgarmtze

Reputation: 25038

MATLAB measure a function run time

How to print the time of a function in MATLAB

example:

%%%TAKE TIME
A = [2 1 3 ; 1 2 5 ;3 5 4 ]
[U,S,V]            = svd(A)
%%%FINISH TIME

whats the syntax?

Upvotes: 5

Views: 13762

Answers (3)

yasin.yazici
yasin.yazici

Reputation: 285

If there are many functions and assignments in your code you may use profile function from matlab library. Before running m file write profile on to command window. After execution check each function's and children function's run time via profile report. You can acquire detailed explanation via help profile.

Upvotes: 1

Jason S
Jason S

Reputation: 189626

you can also use the nonsingleton forms of tic and toc:

tStart=tic;
A = [2 1 3 ; 1 2 5 ;3 5 4 ]
[U,S,V]            = svd(A)
tElapsed=toc(tStart);

This allows the use of more than one timer. (otherwise you have to ensure exclusive use of tic and toc for one measurement)

Upvotes: 13

Dat Chu
Dat Chu

Reputation: 11130

tic()
A = [2 1 3 ; 1 2 5 ;3 5 4 ]
[U,S,V]            = svd(A)
toc()

Upvotes: 12

Related Questions