From charlesreid1

Revision as of 04:36, 25 June 2017 by Admin (talk | contribs) (Created page with "==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, all...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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: