long execution time for simple lines like end and vector value addition
Mostrar comentarios más antiguos

I wanted to make my code more time efficient so looked in the profiler and saw that the most time consuming lines are 'end' and another quite simple line. it is a long loop but other lines in it runs much faster. Does anyone know why they take so long or have an idea how ti improve this loop?
Thanks!
1 comentario
Jan
el 7 de Mayo de 2018
Under Matlab R2016b/Win10_64/i7 I get
sec calls
0.08 2399800 Efoot(n)=Efoot(n-1)+dt*(qin(n-1)+qm_foot-qsk(n-1));
0.08 2399800 Esk(n)=Esk(n-1)+dt*(qsk(n-1)+qm_sk-qout(n-1));
In your example the input data are 4 times bigger, but ths code needs 240 times longer. This is surprising. The main work is done in findpeaks.
Which Matlab version are you using?
Respuesta aceptada
Más respuestas (2)
Jan
el 1 de Mayo de 2018
0 votos
A very important part of the code is missing: Is Efoot and Esk pre-allocated properly? Otherwise the arrays grow iteratively, which is very expensive.
Analysing the run time behavior of a code, which is shown as screenshot and partially only, is a very bold task. I cannot guess e.g., if "qin" is an array or a function. Please post the code as text, such that it can be used by copy&paste, and add some meaningful test data - either by attaching them as MAT file or by some rand() commands with relevant sizes.
1 comentario
Oded Scharf
el 7 de Mayo de 2018
Oded Scharf
el 1 de Mayo de 2018
Editada: Oded Scharf
el 7 de Mayo de 2018
3 comentarios
Jan
el 7 de Mayo de 2018
The run-time of the "end" is not meaningful. It might be an effect of tzhe JIT acceleration (although this is disables as far as I know during profiling?!). To find out more, e.g. if the code can be accelerated, ir would be required to run it, but the posted version does not run:
Undefined function or variable 'Qfoot'.
Error in asd (line 3)
[ Tsk_f, Tfoot_f,ssTsk,ssTfoot,skinrisetime, footrisetime,skp2p ] =...
A proper code formatting would be useful also: Mark the code and press the "{} Code" button.
Oded Scharf
el 7 de Mayo de 2018
Jan
el 7 de Mayo de 2018
Categorías
Más información sobre String Parsing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!