Java 1.5 provides System.nanoTime() to measure time in nano seconds. We can use this to track time taken in nano seconds by a function.

Java Code:
long startTime = System.nanoTime();

// call function
obj.callFunction();

long endTime = System.nanoTime();
long timeDifference = endTime - startTime;