erogol
erogol

Reputation: 13604

Evaluating the performance in time of a specific portion of the matlab code?

I want to be able to measure performance of my code and find the lacking parts. What is the proper way to do that in Matlab? I know I can use just tic: and toc; functions to see the time passing but there might be more convenient way.

Upvotes: 1

Views: 97

Answers (2)

Jonas
Jonas

Reputation: 74930

The most convenient way is to use the GUI profiler tool. You can find it in the dropdown menus (Desktop->Profiler), or you can start it from the command line by typing profile viewer. Then you enter the name of the function at the top of the window, hit "run", and wait till the code is done running. Clicking on the links brings you into the respective function, where you can see runtime line-by-line.

Note that timing code that runs very fast and for only a handful of iterations can be tricky; for these cases you may want to use the timeit function from the Matlab File Exchange.

enter image description here

Upvotes: 3

Yohann
Yohann

Reputation: 6336

The profile tool reports time spent on each function and in each line of code in the program.

It takes longer to implement so if you are analyzing a short piece of code, tic-toc will do the job better.

Upvotes: 1

Related Questions