Measure time in Java JNI ( native call Java)

Viewed 1001

I am trying to measure time in JNI call, it call from native to Java.

In C code, I apply "GetTickCount" api to get JNI execution time and "System.nano" in Java.

Example:

long start = GetTickCount();
....//CallStaticMethod exampleMethod...
long end = GetTickCount();
long duration = end - start;

And in Java

public static exampleMethod(){
    long start = System.nano();
    //do something
    long end = System.nano();
    long duration = TimeUnit.NANOSECONDS.toMilis(end - start);
}

Sometimes, it is inconsistent because the java's duration is more than C's duration. ( about 5 to 10 miliseconds)

2 Answers
Related