フィルターのクリア

How to check efficiency of my code?

7 ビュー (過去 30 日間)
Raviteja
Raviteja 2011 年 9 月 22 日
コメント済み: Luna 2019 年 1 月 28 日
I heard, the command true is faster than logical(1) This I got after reading one answer in this answers forum.
In general how to check efficiency of my code. I usually use to compare 2 programs for the same task by using tic - toc command. Whichever gives lesser time, I use that code in my application.
Here, my question is how to check efficiency of my code in another way(s) ?

回答 (2 件)

Grzegorz Knor
Grzegorz Knor 2011 年 9 月 22 日

Jan
Jan 2011 年 9 月 22 日
The PROFILE command is almost very helpful to measure the execution time of different lines. Unfortuantely it disables the JIT-acceleration, because it can change the order of execution and a the time spent "inside a line" is not meaningful anymore. So especially the accelerated FOR loops get very slow when a PROFILE is created. This might be one reason for the old rumors about slow FOR loops.
CPUTIME measures the time with running CPU. As far as I can see, this reduces the influence of waiting for the harddisk etc. This might be helpful, or useless according to what you want to measure.
There is a nice function in the FEX to measure run-times: TIMEIT. Under Windows you can use the high-accuracy-timer also: HAT.
Finally I'm using TIC TOC also for most measurements. Repeated measurements are required, because there will be some noise.
  1 件のコメント
Luna
Luna 2019 年 1 月 28 日
I was searching about code efficiency, and found that timeit is already built-in so the function in the FEX does not exist anymore.
Putting the link here maybe it helps to someone who searches.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by