I have below code which is predominantly the most expensive in terms of time complexity in my application.
public class Test {
private static final DateTimeFormatter SQL_FORMATTER = DateTimeFormatter.ofPattern("MM/dd/yy HH:mm:ss");
public static void main(String[] args) {
Instant start = Instant.now();
try {
String parsedDate = parseISO8601UtcDateToSqlDateFormat("2000-01-01T00:00:00Z");
System.out.println(parsedDate);
} finally {
long timeTaken = Duration.between(start, Instant.now()).toMillis();
System.out.println("\n\nFinished processing in: "+timeTaken+ " ms!\n");
}
}
public static String parseISO8601UtcDateToSqlDateFormat(String param) {
TemporalAccessor accessor = DateTimeFormatter.ISO_INSTANT.parse(param);
LocalDateTime dateTime = LocalDateTime.ofInstant(Instant.from(accessor), ZoneOffset.UTC);
return dateTime.format(SQL_FORMATTER);
}
}
Date time formatting is consuming 16ms at the minimum.
Whereas my complete application which does a lot of complex processing is done in less than 1ms.
P.S: Question is not related to benchmarking, I just want to understand whether date time parsing with java 8 is really this expensive or am I doing something wrong.
No comments:
Post a Comment