[Matlab] How to obtain the computation time of a function

  • MATLAB
  • Thread starter hurryon
  • Start date
  • #1
9
2

Main Question or Discussion Point

Hi, all.

I have a function in Matlab. I'd like to calculate the computation time of the function. How can I obtain the time? I think Matlab must include related functions as its internal functions.

Thanks in advance.
 

Answers and Replies

  • #2
9
2
Thanks, but "tic" and "toc" provide the elapsed time in seconds. Do you know a way that provides the elapsed time in milliseconds ?

Thanks in advance.
 
  • #3
422
1
A quick and easy way to do this is to use "cputime" to calculate the elapsed time. For instance, suppose that you wanted to determine how long it takes for the matlab benchmark to run. Then you'd use the following:

Code:
time1 = cputime;
bench;
cputime - time1
Obviously, you can substitute "bench" for your function to determine how long it takes to run. See "doc cputime" for more information.
 
  • #4
Hello,
The tool in MATLAB built for this purpose is: "Profile".
In the MATLAB search at: "http://www.mathworks.com/" [Broken]
and typing "profile" will bring up the information.

Main commands are turning it on:
profile on
and viewing the results (after some execution):
profile viewer

kind regards.
 
Last edited by a moderator:

Related Threads for: [Matlab] How to obtain the computation time of a function

Replies
1
Views
4K
Replies
0
Views
5K
Replies
1
Views
2K
Replies
4
Views
2K
Replies
1
Views
3K
Replies
3
Views
2K
Top