long startTime = System.nanoTime(); myMethod(); long endTime = System.nanoTime(); long executionTime = endTime - startTime; System.out.println("Execution time: " + executionTime + "ns");
long start = System.nanoTime(); // some code here long end = System.nanoTime(); long elapsed = end - start; System.out.println("Elapsed time: " + elapsed + "ns");This example measures the elapsed time between two arbitrary points in the program, represented by the `start` and `end` variables. The elapsed time (`elapsed`) is printed out in nanoseconds. The System class is located in the java.lang package, not in the java.io package.