Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to determine the execution time of a script?

Subject: How to determine the execution time of a script?

From: david smith

Date: 5 Dec, 2010 23:34:05

Message: 1 of 3

Hi everyone,

I am working on a project that asks to compare the execution times of two gaussian elimination methods (partial and complete pivoting). The prof wants us to plot out the times for different matrix dimensions.

So the question is: how exactly can I output the times (in seconds) of execution of each script? Is there a function in matlab that can help me do that? Or do I have to write a code in the script to have that output?

Thank you.

Subject: How to determine the execution time of a script?

From: Paulo Silva

Date: 5 Dec, 2010 23:55:04

Message: 2 of 3

"david smith" <demijet01@yahoo.com> wrote in message <idh7hd$cip$1@fred.mathworks.com>...
> Hi everyone,
>
> I am working on a project that asks to compare the execution times of two gaussian elimination methods (partial and complete pivoting). The prof wants us to plot out the times for different matrix dimensions.
>
> So the question is: how exactly can I output the times (in seconds) of execution of each script? Is there a function in matlab that can help me do that? Or do I have to write a code in the script to have that output?
>
> Thank you.

tic;

% your code goes here

TimeSpent = toc;

Subject: How to determine the execution time of a script?

From: Walter Roberson

Date: 5 Dec, 2010 23:57:52

Message: 3 of 3

On 05/12/10 5:34 PM, david smith wrote:

> I am working on a project that asks to compare the execution times of
> two gaussian elimination methods (partial and complete pivoting). The
> prof wants us to plot out the times for different matrix dimensions.
> So the question is: how exactly can I output the times (in seconds) of
> execution of each script? Is there a function in matlab that can help me
> do that? Or do I have to write a code in the script to have that output?

See tic() and tock()

Note: execution times for *scripts* are not representative of how fast
Matlab *can* do the computation, as scripts are not pre-parsed and
compiled in to threaded code (are at least they aren't until the most
recent version of Matlab.)

Execution time of *functions* reflect pre-parsing and compiling down to
threaded calls. However, the first time the function is called, it has
to take the time to do that parsing and that would be included in the
timing.

Therefor in order to fairly time how short Matlab _can_ do the
computation, code in as a function, and execute it at least twice,
discarding the timing of the first execution.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us