I am trying to measure the execution time for several methods. so I was thinking to make a method instead of duplicate same code many times.
Here is my code:
you may do smth like:
private void MeasureExecutionTime(Method m) { startTime = System.nanoTime(); try { m.invoke(classObj, args); } finally { int endTime = System.nanoTime(); } elapsedTime = endTime - startTime; System.out.println("This takes " + elapsedTime + " ns."); }