Check out example codes for "java measure execution time". It will help you in understanding the concepts better.

Code Example 1

Instant start =;
Instant end =;
System.out.println(Duration.between(start, end)); // prints PT1M3.553S

Code Example 2

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

long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.

Learn ReactJs, React Native from