Matlab function with initial long execution time

1 view (last 30 days)
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).
Elapsed time is 111.170418 seconds.
Elapsed time is 0.033134 seconds.
Elapsed time is 0.029289 seconds.

Accepted Answer

patrick1704 on 25 Jul 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:
In general, recompilation is only required when something like
clear all;
is used.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!