From charlesreid1

Notes

This page contains Tim the Timer, a little timing object for Java that wraps calls to the system library. It can accumulate time and report the aggregate total, allowing it to be switched on and off only when operations of interest are being performed.

Code

/** 
 * Tim the timer.
 *
 * "Hi Tim!"
 * "How much Tim - "
 *
 * Tim tim = new Tim();
 * do stuff 
 * tim.elapsedms()
 */
public class Tim {
	double cumulativeTotal, start, end;

    public Tim() {
		cumulativeTotal = 0.0;
		start = 0.0; 
		end = 0.0;;
	}
	public void tic() {
        this.start = System.currentTimeMillis();
	}
	public void toc() {
		this.end = System.currentTimeMillis();
		cumulativeTotal += (end-start);
	}
    public double elapsedms() {
        return cumulativeTotal;
    }
}


Flags





See also: