The first type is measured in milliseconds.
Java code
// Pseudocode
Long starttime = system. currenttimemillis (); // get the start time
Dosomething (); // code snippet for testing
Long endtime = system. currenttimemillis (); // get the end time
System. Out. println ("program running time:" + (end-Start) + "Ms ");
// Pseudocode
Long starttime = system. currenttimemillis (); // get the start time
Dosomething (); // code snippet for testing
Long endtime = system. currenttimemillis (); // get the end time
System. Out. println ("program running time:" + (end-Start) + "Ms ");
The second type is calculated in nanoseconds.
Java code
// Pseudocode
Long starttime = system. nanotime (); // get the start time
Dosomething (); // code snippet for testing
Long endtime = system. nanotime (); // get the end time
System. Out. println ("program running time:" + (end-Start) + "ns ");
// Pseudocode
Long starttime = system. nanotime (); // get the start time
Dosomething (); // code snippet for testing
Long endtime = system. nanotime (); // get the end time
System. Out. println ("program running time:" + (end-Start) + "ns ");
It suddenly reminds me that junit4 can also test the execution time.
This article is reposted by others!
Http://itpx.eol.cn Source: 2010-08-05 large medium small