Skip to content

Instantly share code, notes, and snippets.

@ChenZhongPu
Created June 15, 2021 08:04
Show Gist options
  • Save ChenZhongPu/bdd213fc92b984ebba9849e9173921c7 to your computer and use it in GitHub Desktop.
Save ChenZhongPu/bdd213fc92b984ebba9849e9173921c7 to your computer and use it in GitHub Desktop.
Autoboxing Test
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