Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestNanoTimer2 {
- /**
- * Program: TestNanoTimer2.java
- * Purpose: Time running of a for loop
- * Creator: Chris Clarke
- * Created: 02.10.2015
- */
- private static final int MAX = 10000000; // ten million
- public static void main(String[] args) {
- NanoTimer2 t = new NanoTimer2();
- t.setStartTime();
- // start of test loop
- for (int i=0; i<MAX; i++) {
- double j = i * 2.12345;
- } // end for
- // end of test loop
- t.setRunningTime();
- System.out.println(t.toString());
- } // end main()
- } // end class testNanoTimer2
- class NanoTimer2 {
- /*
- * Class: NanoTimer2.java
- * Purpose: Get program running times
- * Creator: Chris Clarke
- * Created: 03.04.2014 and 02.10.2015
- */
- private long startTime = 0, runningTime = 0;
- public void setStartTime() {
- startTime = System.nanoTime();
- }
- public void setRunningTime() {
- runningTime = System.nanoTime() - startTime;
- }
- public long getRunningTime() {
- return runningTime;
- }
- public String toString() {
- return "Running time: " + getRunningTime() + " ns";
- }
- } // end class NanoTimer2
Advertisement
Add Comment
Please, Sign In to add comment