Matlab function slow first time, much faster subsequently. Why?
Show older comments
I have a large MATLAB function file. It first creates a zero matrix, then updates about 70% of the cells by evaluating a number of corresponding (long) algebraic expressions that are hard coded in the function. Once this is complete, a numeric matrix is returned.
The .m file is about 4MB large (I have 100 of these m. files, but that is not directly relevant). When I evaluate the function the first time, it takes about 9s to evaluate. Subsequent runs, however, only take about 0.1s, which is more what I was expecting.
Why does the first evaluation take 9s? Anytime I close and reopen matlab, I each time have this slow first evaluation, with subsequent runs being much faster. Why is this?
The m. file can be found at the below public link (you can copy the text from the browser): https://dl.dropboxusercontent.com/u/157153767/K_a_12_102x.m
The command window input you should use is: [test]=K_a_12_102x(414000000,1.1095e+09,1.2500e-04,0.0840,0.0840,0.0240,0.0240,0.0020,0.0020,0,0,0,0,3.0397e+08,8.9930e+07,0,3.0397e+08,0,1.0702e+08,0,0,0,0,0,0,497.7389,80.7355,-15.9811,391.1985,-15.9811,103.5248,20440000,0,20440000,0.06)
Accepted Answer
More Answers (0)
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!