Java basic type run time is better than boxed basic type detailed Example description

Source: Internet
Author: User

Package com.effective;

public class Publishtest {


public static void Main (string[] args) {
TODO auto-generated Method Stub


When you mix basic types and boxed basic operations in your program, the boxed base type is automatically removed, resulting in longer program runs and more space
In three cases, the runtime is the least when sum and I are the same long base type
Long Starttime=system.currenttimemillis (); Get Start time, with milliseconds as the unit of calculation
Long sum = 0l;//
System.out.println ("integer.max_value=" +integer.max_value);
for (Long i = 0l; I <= integer.max_value; i++) {
sum + = i;
}
System.out.println ("sum=" +sum);
Long Endtime=system.currenttimemillis (); Get End time
SYSTEM.OUT.PRINTLN ("program Run Time:" + (Endtime-starttime) + "MS");

First: When sum and I are both a long base type
sum=2305843008139952128
Program Run time: 7250ms

Third: When sum is a long boxing base type, and I is a long base type
sum=2305843008139952128
Program Run time: 24622ms

Second: When sum and I are both a long boxing base type
sum=2305843008139952128
Program Run time: 60610ms
}
}

Java basic type run time is better than boxed basic type detailed Example description

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.