A comparison of the time-consuming methods of computing programs running in Java __java

Source: Internet
Author: User

There are two ways to test program code running in Java:

First: measured in milliseconds.

Long Starttime=system.currenttimemillis ();

Here are some test code

for (int i=0;i<10000;i++) {

System.out.println ("At present:" +i);

}

Long Endtime=system.currenttimemillis ();

SYSTEM.OUT.PRINTLN ("Current program time Consuming:" + (Endtime-starttime) + "MS");

Second: measured in nanoseconds.

Long Starttime=system.nanotime ();

Here are some test code

for (int i=0;i<10000;i++) {

System.out.println ("At present:" +i);

}

Long Endtime=system.nanotime ();

SYSTEM.OUT.PRINTLN ("Current program time Consuming:" + (Endtime-starttime) + "ns");


If the test program needs a high precise time, it will usually choose the second type,

If the test program needs general precise time, it will usually choose the first type,


Time Conversion:

1 hours = 60 Minutes

1 minutes = 60 seconds

1 seconds =1000 milliseconds

1 ms =1000 microseconds

1 microseconds =1000 nanosecond

1 nanoseconds =1000 Picosecond

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.