MATLAB Answers


Static vs Object Method Performance Considerations

Asked by Abel
on 18 Oct 2012
Are there any performance considerations regarding Static vs. object methods in MATLAB OOP?


Hi Matt
It's not clear why getc1 should be "slower since it has to parse the static function call test.f".
the point of the example i gave is to determine if it's faster to allocate on-the-fly or declare something constant. It's unambiguous, if you execute the example 10,000 times that it's much better not to use constant declarations in MATLAB OOP. Tiny test are good b/c they limit the factors at play.
Thanks for your additional comments about "the idea of MATLAB" and my "wrong" coding practices. You'll learn eventually, after you've used MATLAB long enough, that you can't vectorize everything. ;)
@Matt J, It used to be that vectorization was the be all and end all of MATLAB since loops were slow. For over 10 years now MATLAB has had a JIT accelerator which often makes loops the same speed (and sometimes faster) than vectorized code.
@Abel - the problem with your test, though, is that even though you've declared your data constant, you have to execute the command "test.f" to access the data. This is something like calling an mfile function, I'd assume, and there is overhead associated with that. When the data you're processing is small in comparison to the overhead needed to access it, you get misleading results. I believe you even encountered the same issue here
@Daniel - the JIT has its benefits, bit it hasn't leveled the playing field completely. It will always be true, I think, that in a loop, if a function is given too small a chunk of data to process, the overhead from just launching the function (repeatedly) will kill you.

Sign in to comment.


1 Answer

Answer by Daniel Shub
on 19 Oct 2012

Dave Foti who manages the OOP group at TMW has a post on Loren's blog that touches on some of these issues.
For your example I am not sure how smart the MATLAB JIT accelartor is and when things get reallocated and refreshed. It seems to me that once getc1 and getc2 are loaded into memory (remember MATLAB parses and loads functions into memory), that they are identical.


Sign in to comment.