Reproduced from www.java3z.com: Unknown
Our general Java runtime timingCodeYes:
Long begintime = system. currenttimemillis ();
// Operation code
Long endtinme = system. currenttimemillis ();
Long costtime = (endtime-begintime );
However, if the computing time is very short (the current machine is too powerful. currenttimemillis () is the number of milliseconds from January 1, 1970 to the present. It is estimated that many decimal places should be omitted. I have not read the code and guessed it. The result is usually 0 and cannot be displayed.AlgorithmTime consumed. At this time, nanotime () and nanoseconds can be used.
The code above is changed:
Long begintime = system. nanotime ();
// Operation code
Long endtime = system. nanotime ();
Long costtime = (endtime-begintime)/1000;
// To convert the value to microseconds, you can divide it by 1000.