Created
June 15, 2021 08:04
-
-
Save ChenZhongPu/bdd213fc92b984ebba9849e9173921c7 to your computer and use it in GitHub Desktop.
Autoboxing Test
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
import java.time.Duration; | |
import java.time.Instant; | |
public class BoxTest { | |
private static long sum1() { | |
long sum = 0L; | |
for (long i = 0; i < Integer.MAX_VALUE; i++) { | |
sum += i; | |
} | |
return sum; | |
} | |
private static long sum2() { | |
Long sum = 0L; | |
for (long i = 0; i < Integer.MAX_VALUE; i++) { | |
sum += i; | |
} | |
return sum; | |
} | |
public static void main(String[] args) { | |
Instant start = Instant.now(); | |
sum1(); | |
Instant end = Instant.now(); | |
System.out.println(Duration.between(start, end).toMillis()); | |
start = Instant.now(); | |
sum2(); | |
end = Instant.now(); | |
System.out.println(Duration.between(start, end).toMillis()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment