how to calculate the execution time of program?

 Respuesta aceptada

Dishant Arora
Dishant Arora el 25 de Feb. de 2014
tic
yourCode
timeElapsed = toc

6 comentarios

Thanks sir...this helped us a lot.
Mateus Habermann
Mateus Habermann el 20 de Sept. de 2017
Thanks!
bach sy
bach sy el 27 de Jul. de 2018
Thank you so much
N/A
N/A el 13 de Mayo de 2019
Thaanks!!!
AVINASH PANDEY
AVINASH PANDEY el 12 de Nov. de 2021
thanku for the information. However, if we repeatedly run the code we get different elapsed time each time. Any explanation regarding this will be highly appreciable.
Steven Lord
Steven Lord el 12 de Nov. de 2021
Some minor variation is to be expected. One potential cause of variation is different other processes running at the same time your MATLAB code is running. If you're on Microsoft Windows and Windows Update chooses exactly the time you're running your code to "phone home" for updates that obviously consumes some of the computer's attention, thus potentially making your MATLAB code take longer to run.

Iniciar sesión para comentar.

Más respuestas (4)

Aaron Corbin
Aaron Corbin el 1 de Mzo. de 2014
Editada: Aaron Corbin el 1 de Mzo. de 2014

1 voto

You could also do the following:
before1=clock code... etime(clock,before1)
It subtracts the time before from the time after.
Laith Mohammed
Laith Mohammed el 16 de Nov. de 2019

1 voto

First you put tic and entering the code that you are working on it after that toc,
Finaly, create a variable called Elapsed_time = toc
Or, you can just wait and matlab will tell you that elapsed time is (XX seconds)
Steven Lord
Steven Lord el 12 de Nov. de 2021

0 votos

tic and toc is one way to measure the performance of your code. Other ways include the timeit function and the Profiler.
Barsom
Barsom el 21 de Oct. de 2024

0 votos

Write a program that reads the departure time of a train and the arrival time and computes and displays the trip time.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 25 de Feb. de 2014

Respondida:

el 21 de Oct. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by