如果您决定用MATLAB编写实现,那么这里有一些非常好的@AndrewJanke分,这是关于MATLAB中OOP性能的绝佳答案(值得阅读整篇文章):
Mimicking a C++ or Java class in MATLAB probably won’t be optimal.
Java/C++ classes are typically built such that objects are the
smallest building blocks, as specific as you can (that is, lots of
different classes), and you compose them in arrays, collection
objects, etc, and iterate over them with loops. To make fast MATLAB
classes, turn that approach inside out. Have larger classes whose
fields are arrays, and call vectorized methods on those arrays.
The point is to arrange your code to play to the strengths of the
language – array handling, vectorized math – and avoid the weak spots.
为了回答您的问题,我引用了文档:
At MATLAB startup, part of the MATLAB virtual address space is
reserved by the Java Virtual Machine (JVM) and cannot be used for
storing MATLAB arrays.
因此它仅在启动时初始化一次.
与M文件不同,调用Java方法时也会产生开销(因为必须将MATLAB类型与Java数据类型进行编组).
现在,如果您想充分利用性能,请确保将Java方法调用为:
func(obj)
代替:
obj.func()