Thursday, September 2, 2010

Java program running on the computing time

suddenly want accurate test execution time of Java code, on the Internet for a while. There are basically two ways found. But do not know the best. Oh, I hope we can you direct me. The first one is calculated in milliseconds. Java code / / pseudo code for long startTime = System.currentTimeMillis (); / / get start ...
Suddenly want accurate test execution time of Java code, on the Internet for a while. There are basically two ways found. But do not know the best. Oh, I hope we can you direct me.
The first one is calculated in milliseconds.

Java code



/ / Pseudo code

long startTime = System.currentTimeMillis (); / / Get start time

doSomeThing (); / / test code

long endTime = System.currentTimeMillis (); / / Get end time

System.out.println ("run time:" + (end-start) + "ms");

/ / Pseudo code

long startTime = System.currentTimeMillis (); / / Get start time

doSomeThing (); / / test code

long endTime = System.currentTimeMillis (); / / Get end time

System.out.println ("run time:" + (end-start) + "ms");

The second is calculated in units of nanoseconds.

Java code

/ / Pseudo code

long startTime = System.nanoTime (); / / Get start time

doSomeThing (); / / test code

long endTime = System.nanoTime (); / / Get end time

System.out.println ("run time:" + (end-start) + "ns");

/ / Pseudo code

long startTime = System.nanoTime (); / / Get start time

doSomeThing (); / / test code

long endTime = System.nanoTime (); / / Get end time

System.out.println ("run time:" + (end-start) + "ns");

Suddenly remembered Junit4 can also test execution time, huh, huh

No comments:

Post a Comment