I am new to JNI (or Native Language programming) and would appreciate any help in this. Here's what I am trying to do and along with the execution times.
I am trying to find sum of the array elements of doubles of size 100,000,000 and trying to get JNI to get it faster.
For Java (Pure Java), it takes 154ms For C (Pure C), it takes 0 ms For JNI (Java calls Native C), it takes 800 ms
I understand that JNI would have its own performance overhead but I take the time it takes to execute JNIEXPORT jdouble JNICALL Java_Sample1_sum
only 1 ms
(i.e. after the control enters and before it leaves this sum method), so my question is is JNI so slow that it takes about 799 ms to call the JNI itself i.e. the following block takes 800 ms
start = System.currentTimeMillis();
sample.sum(doubleArray);
end = System.currentTimeMillis();
I can share my entire code, if this doesn't help in answering. Also, I have searched about optimizing JNI.