Matlab function with initial long execution time
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mohammad Shojaei Arani
le 25 Juil 2022
Commenté : Mohammad Shojaei Arani
le 26 Juil 2022
Hello,
When I run a function handle its execution time is initially very long but in the second, third, etc runs its execution time is normal (sometimes, however, I see that the lnog initial execution time will happen again in later runs but this does not happen very frequently).I have seen this problem when I work with symbolic expressions but did not expect to see this in matlabfunctions. I would like to know whether there is a way to avoid this? Or, is there something like 'loading the file' (or similar concepts) prior to executing the matlab function to avoid this?
In the following, you see an example about my question (the matlab function EZ_CC_3_11 is attached).
n=10;
Dm0=rand(1,n);Dm1=rand(1,n);Dm0=rand(1,n);Dm2=rand(1,n);Dm3=rand(1,n);Ds0=rand(1,n);Ds1=rand(1,n);Ds2=rand(1,n);Ds3=rand(1,n);
tic;EZ_CC_3_11(Dm0,Dm1,Dm2,Dm3,Ds0,Ds1,Ds2,Ds3);toc;
Elapsed time is 111.170418 seconds.
tic;EZ_CC_3_11(Dm0,Dm1,Dm2,Dm3,Ds0,Ds1,Ds2,Ds3);toc;
Elapsed time is 0.033134 seconds.
tic;EZ_CC_3_11(Dm0,Dm1,Dm2,Dm3,Ds0,Ds1,Ds2,Ds3);toc;
Elapsed time is 0.029289 seconds.
Thanks,
Babak
0 commentaires
Réponse acceptée
patrick1704
le 25 Juil 2022
Matlab uses a just-in-time compiler that compiles the code at first execution and basically creates the executable code. This is reused for all subsequent evaluation. You can find some documentation here: https://www.mathworks.com/products/matlab/matlab-execution-engine.html
In general, recompilation is only required when something like
clear all;
is used.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!