Static vs Object Method Performance Considerations
이전 댓글 표시
Are there any performance considerations regarding Static vs. object methods in MATLAB OOP?
댓글 수: 6
Daniel Shub
2012년 10월 18일
To clarify, you have a method that could be static, but you are thinking of passing it the object, and then not using the object?
Abel
2012년 10월 18일
Matt J
2012년 10월 18일
The example is so tiny, I can't imagine that you could get any meaningful timing comparison out of it. Also getc1 could be expected to be slower because it has to parse the static function call test.f
Aside from these observations, if you're doing something where the speed of a function call is the bottleneck, you're probably coding things the wrong way. The idea of MATLAB is you try to vectorize computations and deploy them in just a few function calls, rather than through many repeated function calls.
Abel
2012년 10월 19일
Daniel Shub
2012년 10월 19일
@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.
답변 (1개)
Daniel Shub
2012년 10월 19일
1 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!