From: Ed Yu on
Hi Daniel,

Here is a thread that I posted a while back...

http://www.mathworks.com/matlabcentral/newsreader/view_thread/246361#639453

Which describes MATLAB invokes com.mathworks.jmi.OpaqueJavaInterface.doesMethodExist() whenever a java method is invoked which generates a large amount of temporary objects of class java.lang.Appendable when calling java method frequently.

In your case, the time spend is mostly due to data marshalling (I think). One of the lesser known things is how MATLAB "create" copies of data to and from java objects. You may need to hook up a profiler and output timestamp at the end of your java routine (java side) and also output timestamp after the m-code that invoke your java routine. Using MATLAB profiler would also be helpful when trying to determine where time is spent during m-code execution.

Good luck!

Ed.

"Daniel Armyr" <firstname(a)lastname.se> wrote in message <hroprv$j6o$1(a)fred.mathworks.com>...
> Hi.
> For the last couple of years now, I have been running an algorithm that I coded in java from inside matlab. It takes two matrices of up to 1000x1000 elements and returns a java object containing three matrices of approximately 100x100 elements each.
>
> Yesterday I was in a debate about the efficiency of my algorithm and went back to test it more carefully. I was astonished to find that there is an overhead of almost 160ms for each call to my java function. Is there a reason for this overhead? I have come to understand (from my collegues benchmarking of his competing mex-implementation) that the overhead when calling a mex file is insignificant compared to this?
>
> Any thoughts on that?
>
> Sincerely
> Daniel Armyr.