I need to measure the time it takes for a function to complete in Java. How can I do that?
I want to measure the function's time consumption, not that of the full program.
long start = System.nanoTime();
methodToBeTimed();
long elapsedTime = System.nanoTime() - start;