Вот несколько способов найти время выполнения в Java:
1) System.nanoTime ()
long startTime = System.nanoTime();
.....your code....
long endTime = System.nanoTime();
long totalTime = endTime - startTime;
System.out.println("Execution time in nanoseconds : " + totalTime);
System.out.println("Execution time in milliseconds : " + totalTime / 1000000);
2) System.currentTimeMillis ()
long startTime = System.currentTimeMillis();
.....your code....
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println("Execution time in milliseconds : " + totalTime);
3) Instant.now ()
long startTime = Instant.now().toEpochMilli();
.....your code....
long endTime = Instant.now().toEpochMilli();
long totalTime = endTime - startTime;
System.out.println("Execution time in milliseconds: " + totalTime);
или
Instant start = Instant.now();
.....your code....
Instant end = Instant.now();
Duration interval = Duration.between(start, end);
System.out.println("Execution time in seconds: " +interval.getSeconds());
4) Date.getTime ()
long startTime = new Date().getTime();
.....your code....
long endTime = new Date().getTime();
long totalTime = endTime - startTime;
System.out.println("Execution time in milliseconds: " + totalTime);