package jutil;

/**
 * The class contains primitive utilities for profiling
 * method calls. They are primitive because they count
 * all time elapsed, not just the time consumed by the
 * thread running the method call.
 */
public class Profiler {
	/**
	 * The timer
	 */
	private static long startTime;
	/**
	 * Call this method just before the method call you want
	 * to time.
	 * @param msg  A message to display when timer starts
	 */
	public static void start(String msg) {
		System.out.println(msg);
		startTime = System.currentTimeMillis();
	}
	/**
	 * same as start but with no message.
	 */
	public static void start() { start(""); }
	/**
	 * Call this method immediately after the method call. It displays
	 * the elapsed time.
	 * @param msg   An additional message to display
	 */
	public static void stop(String msg) {
		System.out.println(msg + ": duration = " + (System.currentTimeMillis() - startTime) + " ms");
	}
	/**
	 * Same as start with no message.
	 */
	public static void stop() { stop(""); }
}