(New page: <source lang="java"> * * Compute time duration. * This class is generally used for analyzing the performance of the part of the program.: public class ExecutionTimer { private long...)
 
 
Line 7: Line 7:
 
private long start;
 
private long start;
 
private long end;
 
private long end;
 +
 
public ExecutionTimer() {
 
public ExecutionTimer() {
 
reset();
 
reset();
 
start();
 
start();
 
}
 
}
 +
 
/**
 
/**
 
* Reset timer.
 
* Reset timer.
Line 18: Line 20:
 
end = 0;
 
end = 0;
 
}
 
}
 +
 
/**
 
/**
 
* Set start.
 
* Set start.
Line 26: Line 29:
 
start = System.nanoTime();
 
start = System.nanoTime();
 
}
 
}
 +
 
/**
 
/**
 
* Set end.
 
* Set end.
Line 35: Line 39:
 
return this;
 
return this;
 
}
 
}
 +
 
/**
 
/**
 
* Get duration.
 
* Get duration.
Line 43: Line 48:
 
return (end - start) / 1000000.0;
 
return (end - start) / 1000000.0;
 
}
 
}
 +
 
public void doAll(String notation) {
 
public void doAll(String notation) {
 
System.out.println(notation + " ---> " + ((System.nanoTime() - start) / 1000000.0));
 
System.out.println(notation + " ---> " + ((System.nanoTime() - start) / 1000000.0));

Latest revision as of 05:53, 23 November 2010

/**
 * Compute time duration.
 * This class is generally used for analyzing the performance of the part of the program.
 */
public class ExecutionTimer {
	private long start;
	private long end;
 
	public ExecutionTimer() {
		reset();
		start();
	}
 
	/**
	 * Reset timer.
	 */
	public final void reset() {
		start = 0;
		end = 0;
	}
 
	/**
	 * Set start.
	 */
	public final void start() {
		//----- do not use currentTimeMillis method (it is totally inaccurate)
//		start = System.currentTimeMillis();
		start = System.nanoTime();
	}
 
	/**
	 * Set end.
	 * @return
	 */
	public ExecutionTimer end() {
//		end = System.currentTimeMillis();
		end = System.nanoTime();
		return this;
	}
 
	/**
	 * Get duration.
	 * @return
	 */
	public double duration() {
		//----- in millisecond
		return (end - start) / 1000000.0;
	}
 
	public void doAll(String notation) {
		System.out.println(notation + " ---> " + ((System.nanoTime() - start) / 1000000.0));
		start();
	}
}


Back to JavaHowTo

Alumni Liaison

Basic linear algebra uncovers and clarifies very important geometry and algebra.

Dr. Paul Garrett