The reason behind the question
For a physics-project, we want to analyze two surfaces (specified by a bunch of vertices) and calculate the volume between those surfaces. To be able to do this, we want to implement a two-dimensional interval-search tree. In total the asymptotic run time, will be close to O(n2log n).
The question
In summary we are going to implement an algorithm, which will be quite time-expensive. Furthermore, the algorithm doesn’t profit from the highly optimized math libraries in matlab. Therefore, we are considering to call Java from matlab. Conclusively we would like to know:
"To what degree is Java faster than matlab, ignoring the highly optimized performance from the math libraries in matlab?"
and
"Is there any significant delay when repeatedly calling a java method from matlab?"
e.g. does the JVM have to be started every time the method is called? does the jar have to be loaded every single time the method is called?
I hope some of you could help me (and maybe others) with this question.
If you decide to write the implementation in MATLAB, here are some very good points @AndrewJanke made in an excellent answer regarding OOP performance in MATLAB (worth reading the whole post):
To answer your questions, and I quote the documentation:
so it is only initialized once at startup.
Also there is an overhead when calling Java methods as opposed to M-files (since MATLAB types have to be marshalled to and from Java data types).
Now if you want to squeeze out every last bit of performance, make sure to call Java methods as:
instead of: