Why does instatiating more instances of a MATLAB class take a shorter time in MATLAB 7.9 (R2009b)?

1 view (last 30 days)
I am using a class in MATLAB that I wrote. I find that if I create 10 objects of that class at once, then create 20 objects of that class, the first set of operations actually takes longer. TIC and TOC verify the observed behavior.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 3 Mar 2010
The reason for this somewhat odd result can be attributed due to the slow nature of the loading of a MATLAB class the first time. The first time MATLAB loads a new class, it has to do extra processing compared to successive loads. On successive loads, all the class information is already cached, so it is much faster. If you put a "clear classes" statement between the two operations, you will find that the second operation will take longer than the first, due to the fact that the second operation also has to load the class from scratch.

More Answers (0)

Categories

Find more on Construct and Work with Object Arrays in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!