MATLAB: Difference between revisions

From David's Wiki
No edit summary
Line 9: Line 9:


=== Timing Code ===
=== Timing Code ===
[https://www.mathworks.com/help/matlab/matlab_prog/measure-performance-of-your-program.html Reference]
[https://www.mathworks.com/help/matlab/matlab_prog/measure-performance-of-your-program.html Reference]<br>
<code>tic</code> starts a timer. <code>toc</code> returns the time elapsed in seconds since the started timer.
<code>tic</code> starts a timer. <code>toc</code> returns the time elapsed in seconds since the started timer.
<syntaxhighlight lang="matlab">
<syntaxhighlight lang="matlab">

Revision as of 09:53, 29 September 2019


Usage

Anonymous Functions

Reference

sqr = @(x) x.^2;

Timing Code

Reference
tic starts a timer. toc returns the time elapsed in seconds since the started timer.

timerVal = tic
   % The program section to time. 
elapsedTime = toc(timerVal)