Very slow function, excessive overhead?
Afficher commentaires plus anciens
I've got a function that looks at a n x 2 array (1st column time vector, 2nd column flag vector) and it's running incredibly slow. As you can see, line 17 takes almost all of the runtime. I've read that this could be related to overhead, but I don't actually know what that means or how to improve it. Any ideas on what could be causing this?

Réponse acceptée
Plus de réponses (1)
The inner while loop is not necessary: if flag(i,2)-flag(i-1,2) == 1, then of course flag(i,2)-flag(i-1,2) ~== -1. Thus the incrementation i = i+1 will always happen. This is strange since you increment i again after you quit the if-clause.
Preallocating "events" as zeros(size(flag,1),3) and finally cutting it by events = events(1:j-1,:) might speed up the function also.
1 commentaire
Jesse
le 27 Mar 2023
Catégories
En savoir plus sur Graphics Performance dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!