How to find computational time?

I want to find the computation time for the Add in below code. How can I do that? Is there any command?
I can use tic & toc which will give the elapsed time. but I want to find computation / execution time.
Does anyone know? Please help me.
Matlab code
A=[1 2 3 4 56 7 8 9];
B=[7 8 9 4 55 1 2 3];
tic
for i=1:length(A)
Add(i) = A(i)+ 2* B(i);
end
toc

1 Commento

What is the difference between elapsed time and computation time? Of course your computer is also doing all kinds of stuff in the background and I'm not sure we can figure out the percentage of time it spent on only your MATLAB code. But what does it matter? It's the elapsed time that really matters in the real world, right?

Accedi per commentare.

 Risposta accettata

KSSV
KSSV il 12 Dic 2021
Modificato: KSSV il 12 Dic 2021
Read about tic toc.
t1 = tic ;
A=[1 2 3 4 56 7 8 9];
B=[7 8 9 4 55 1 2 3];
for i=1:length(A)
Add(i) = A(i)+ 2* B(i);
end
t1 = toc(t1)
t1 = 0.0289
Also read about profilier and timeit.

Più risposte (2)

Les Beckham
Les Beckham il 12 Dic 2021

0 voti

You might be looking for cputime()
Nasser Almabrok
Nasser Almabrok il 9 Feb 2024

0 voti

I think you are looking for the time taken for the process to finish or to stop for one cycle. tic toc is your answer.

Categorie

Prodotti

Release

R2021b

Richiesto:

il 12 Dic 2021

Risposto:

il 9 Feb 2024

Community Treasure Hunt

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

Start Hunting!

Translated by