I have a bit of code which runs in 10.919 s. Profiling it shows that 10.182 s are wasted in
opaque.double
Which is called when I use
jClass.GetArrays(jArray1,jArray2);
struct.prop1 = double(jArray1);
struct.prop2 = double(jArray1);
What can be done? I have to use Java to interact with external API.
EDIT: I used the following hack:
struct.prop1 = cell2mat( cell( jArray1) );
And got down to 1.5s / 2.2s
EDIT:
Making the java return long comma delimited string representation of the arrays and then using
data = strread(char(jString),'%f','delimiter',',' );
Produced almost bearable performance
-
You might consider saving it to a file, then reading it in on the other end. It might also be similarly slow (especially if a network is involved), but it's worth a shot.
You might also consider converting it to a blob of binary data, then passing it, and converting it back.
I have a sneaking suspicion that with that bad performance it's passing each element of the array in its own transaction rather than all at once.
-
The problem lays in the usage of boxed Java primitives - java.lang.Double in this case.
Simply changing the signature of the Java from Double to double cause Matlab to seamlessly work with the array without the casting overhead.
0 comments:
Post a Comment