Created
November 26, 2016 13:17
-
-
Save odrotbohm/d1a0335a196c6c3146b420c9351533fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2016 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package org.example.myapi; | |
import java.text.DateFormat; | |
import java.text.SimpleDateFormat; | |
import java.time.LocalDateTime; | |
import java.time.format.DateTimeFormatter; | |
import java.util.Date; | |
import java.util.TimeZone; | |
import org.junit.Test; | |
public class DateFormattingTests { | |
private static final int ITERATIONS = 5000000; | |
@Test | |
public void testname() { | |
LocalDateTime now = LocalDateTime.now(); | |
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME; | |
long startTime = System.currentTimeMillis(); | |
for (int i = 0; i < ITERATIONS; i++) { | |
formatter.format(now); | |
} | |
long duration = (System.currentTimeMillis() - startTime); | |
System.out.println("Converting LocalDateTime took " + duration + "ms"); | |
} | |
@Test | |
public void testname2() { | |
TimeZone tz = TimeZone.getTimeZone("UTC"); | |
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'"); // Quoted "Z" to indicate UTC, no timezone offset | |
df.setTimeZone(tz); | |
Date now = new Date(); | |
long startTime = System.currentTimeMillis(); | |
for (int i = 0; i < ITERATIONS; i++) { | |
df.format(now); | |
} | |
long duration = (System.currentTimeMillis() - startTime); | |
System.out.println("Converting Date took " + duration + "ms"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Converting Date took 3944ms | |
Converting LocalDateTime took 18020ms |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment