Why does adding a class to a package significant slow down performance?
Show older comments
I have an application where I am loading a large amount of data from a test instrument (~40mb), extracting the data I need, fitting it to a curve, and performing some additional simple analyses. I converted the code from m-file functions to a classdef with a minimal performance hit. However, when I added the classes and functions to a package ("+" notation), the time to execute increased dramatically. The only difference was whether or not the top-level directory was formatted as a package and imported vs. putting it on the Matlab path. All of underlying code (including fully OO classes) were the same in either case.
One thing note that is specific to my case is that there is a core analysis function that is run ~300 times, with some sub-functions running ~2700 times. I believe that the inefficiencies are coming from calling this function from within the package.
I have used the profiler to eliminate as many inefficiencies as possible. This includes pre-allocation, removing redundant function calls, etc.
Any explanation for the large performance drop? Any suggestions for working around it?
4 Comments
Sean de Wolski
on 3 Jan 2013
Hi Jordan,
Please contact us with a simple example and reference this thread.
%Sean
per isakson
on 4 Jan 2013
Edited: per isakson
on 10 Jan 2013
I've made a simple code (R2012a) based on your description. With and without IMPORT and with and without the accelerator/JIT on (undocumentedmatlab.com). I see no significant differences. 14 seconds in all cases with a million iteration in the innermost loop.
>> feature('accel','off')
>> SignificantlySlower_test
ans =
13.3328 13.3486
>> feature('accel','on')
>> SignificantlySlower_test
ans =
14.6540 14.7412
Pierre
on 10 Jan 2013
Hello everyone,
I have the same problem (I use R2009b). And a similar performance problem append when doing a "cd" of directory containing (lot of) packages...
Sean, do you have some tips ? Thanks,
Pierre
Daniel Shub
on 10 Jan 2013
@pierre post this as a new question. Please include all the details needed to recreate the problem. Ideally a single MATLAB script that would create a folder with a bunch of packages and time the cd compared to a folder with a bunch of subfolders.
Answers (0)
Categories
Find more on Whos in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!