Performance in object-oriented matlab code

버전 1.2.0.0 (22.1 KB) 작성자: Dimitrios Korkinof
A very simple example to demonstrate an observation of mine regarding the use of classes in matlab.
다운로드 수: 654
업데이트 2013/4/18

라이선스 보기

This is a very simple demo made solely for the purpose of demonstrating the high overhead that seems to be induced when using object-oriented programming in Matlab. The problem is especially intense when having classes containing a lot of data and one or more functions in the class need to be frequently
called.

I have implemented 2 distinct scenarios using classes. According to the first (C1), the class contains a large array, let's say 200x200. A function member of the class putting a random number in one element at a time. In the second scenario (C2), the class member function is not modifying the large array, but puts random value in another variable member of the class.

In both cases we call the class member functions 40.000 times and time the code. We also time the actual duration of the core operation without the use of functions or classes, in order to measure the overhead induced in each case.

Fortunately, there is an alternative to using classes in Matlab. The construction is a form of class consisted of nested functions, the handlers to which are made externally available. Of course, inheritance is not available in this case, however this construction is similar enough.

Is there something I am missing here? Is this normal or expected? If not, could something have been done to boost performance?

I am looking forward to your comments!

인용 양식

Dimitrios Korkinof (2026). Performance in object-oriented matlab code (https://kr.mathworks.com/matlabcentral/fileexchange/41349-performance-in-object-oriented-matlab-code), MATLAB Central File Exchange. 검색 날짜: .

MATLAB 릴리스 호환 정보
개발 환경: R2013a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Software Development Tools에 대해 자세히 알아보기
버전 게시됨 릴리스 정보
1.2.0.0

Taking into consideration the accurate comments below, I have added two examples with "handle classes" and corrected a small mistake that resulted in the class member data not actually being updated.

1.0.0.0