Is it possible to change the 'ClockPrecision' setting of MATLAB's Profiler?

The default ClockPrecision value is apparently 0.001 seconds. If a function or line takes less time than that, it registers as 0. I'm trying to assess the efficiency of a few different algorithms to compare them, but none of them take long enough to round up to 1 millisecond. I could not find any way to change this, since it isn't one of the options like 'timer' and 'history' according to the documentation page:
However, I did find this page:
which does not describe how to change the setting, but shows a different value (100 nanoseconds) than what I have (1 millisecond). I'm hoping that means it can be changed, but I can't figure out how.
Thanks in advance for any help.

 採用された回答

John D'Errico
John D'Errico 2015 年 6 月 25 日
編集済み: John D'Errico 2015 年 6 月 25 日

1 投票

Use timeit instead to test and compare specific code blocks. It does various things to make that test far more accurate than the profiler. Steve Eddins had at written at posted it on the file exchange, but it is now part of MATLAB, so no download is needed at all.
While the profiler is very nice and very useful to identify problems in your code, you need a tool like timeit to truly optimize performance once you know where the problem lies.

5 件のコメント

Nathan
Nathan 2015 年 6 月 25 日
Great suggestion, thank you! I looked at the help documentation for timeit and found tic and toc too, which also seem very convenient. Is timeit more accurate than tic and toc, or is there a reason to prefer one over another?
Walter Roberson
Walter Roberson 2015 年 6 月 25 日
tic and toc record how long one particular execution took. timeit runs the code many times to reduce the uncertainty of measurement and effects such as the time it can take to parse code the first time it is encountered.
John D'Errico
John D'Errico 2015 年 6 月 25 日
IMHO, do NOT use tic and toc for any kind of accurate assessment.
The problem is that there are many reasons why a time assessor may mis-estimate the time taken.
1. On modern CPUs, there are many things happening at once. Stuff happens in the background, often at random. Be careful not to use your web browser or check your mail in the middle of a long time test. You need to make multiple calls to the code to try to average the noise out. Timeit is intelligent, running code that is fast MANY times inside a loop to get the most benefit from variance reduction in a large sample.
2. The first call to a function will always be slower than successive calls, because MATLAB must parse the code and put it into cache. In fact the second call is often a bit slower too. So I often tend to do several time tests to make sure I am seeing a stable prediction. I recall that timeit actually runs your code several times up front (tossing out the time for those initial calls) just for this reason.
3. A code block timed directly at the command line may be different in terms of the time required for code inside a function. This is because the parser may be able to optimize code when it does the parsing, whereas code typed in on the command line see no such benefit. Since code passed into timeit is run as a function inside the function, I believe it will yield a better estimate of how you will be using it because it takes full advantage of any acceleration that will happen.
So given that timeit is available, I would always use it preferentially. I do use tic and toc occasionally, but only for places where I just want to report a rough estimate of the time taken.
Nathan
Nathan 2015 年 6 月 26 日
Thanks very much for the explanations. I tried them both but they always disagreed. It's good to know a little about what's going on "under the hood."
Walter Roberson
Walter Roberson 2015 年 6 月 26 日
Later versions of MATLAB can do a fair bit more optimization of expressions at the command line, apparently. For many years, commands at the command line and code in scripts were unoptimized.

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

その他の回答 (1 件)

Philip Borghesani
Philip Borghesani 2015 年 6 月 26 日
The ClockPrecision is based on the timer used, change the profile timer source for a different precision. If you have access to R2015b the processor timer gives the highest precision.
profile -Timer real %

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by