I read from several other reports that people usually get around 480 ns on a simple, basic JNI call:
From What makes JNI call slower?
For common methods, last year, I found calls an average of 40 ns on my Windows desktop and 11 ns on my Mac desktop.
Out of Possible Performance Improvements Using JNI?
However, JNI calls often take about 30 ns.
When I call simple methods in my JNI code (simple I mean no more than one time int argument returning an int type), I get a round-trip call time (measured using System.nanoTIme) between 50,000 - 80,000 ns.
If I do a warm-up of a virtual machine and start a call several hundred times before synchronizing it, I still get about 2000-4000 ns (below 800-1000). (As stated above, I heard others report 100 ns .. and have 10-20 times more than what happens with frequent calls.)
Is this normal speed? What could be the reason that my own code will be called so slower?
UPDATE:
JNIEXPORT jint JNICALL Java_com_snap2d_gl_RenderControl_correctGammaNative (JNIEnv *env, jobject obj, jint pixel) { return X2D_correctGamma(pixel, 1.0f); }
Where X2D_correctGamma (int, float) is a method for correcting the value of the gamma of pixels (I have implemented my own code since publication).
Java performance test:
for(int i = 0; i < 100; i++) { long t1 = System.nanoTime(); correctGammaNative(0xFFF); long t2 = System.nanoTime(); System.out.println(t2 - t1); }
This is the warm-up code. Most prints are read by 800-1000ns after the initial call.
Unfortunately, I may have to abandon this because it should be used for rendering, and calling it thousands of times per second will reduce the frame rate to 1 FPS.
System Information:
It works similarly: JDK1.6.0_32 (64-bit), JDK1.7.0_04 (64-bit) and JRE1.7.0_10 (32-bit)
Windows 7 64-bit
RAM 16 GB
i7-3770 Quad Core @ 3.4-3.9ghz
GNU GCC MinGW Compilers (32-bit and 64-bit)