I tried to implement a counter using Java 8's LocalTime and Instant, both works fine but the output is a bit confusing! when ever I use Instant I got smaller values for the same loop ? any idea?
// using Instant
Instant before=Instant.now();
// something time consuming
for(int i=1;i<100000000;i++);
Instant after=Instant.now();
Duration duration=Duration.between(before, after);
System.out.println(duration.toMillis());
// using LocalTime
LocalTime xBefore=LocalTime.now();
for(int i=1;i<100000000;i++);
LocalTime yAfter=LocalTime.now();
System.out.println(ChronoUnit.MILLIS.between(xBefore, yAfter));