I/T/Java2009.11.24 09:51
실행 시간을 측정하는 코드 입니다.
mode parameter 값을 통해서 원하는 시간 방식으로 값을 얻을 수 있습니다.

package keepburning;

/**
 * @Project	: Blog
 * @Name : ExecutionTime.java
 * @Date : 2008. 08. 13
 * @Author : Keep Burning
 * @Blog : http://keepburning.tistory.com
 * @Description : Estimate execution time
 */
public class ExecutionTime {
	public final static int MilliSecondMode	= 0;
	public final static int SecondMode		= 1;
	public final static int MinuteMode		= 2;
	public final static int HourMode		= 3;
	public final static int DayMode			= 4;
	
	private static long start;
	
	public static void startTimer() {
		start = System.currentTimeMillis();
	}
	
	public static float endTimer(int mode) {
		long elapsedTimeMillis = System.currentTimeMillis()-start;
		if(mode==MilliSecondMode) {
			
		} else if(mode==SecondMode) {
			return elapsedTimeMillis/1000F;
		} else if(mode==MinuteMode) {
			return elapsedTimeMillis/(60*1000F);
		} else if(mode==HourMode) {
			return elapsedTimeMillis/(60*60*1000F);
		} else if(mode==DayMode) {
			return elapsedTimeMillis/(24*60*60*1000F);
		}
		return elapsedTimeMillis;
	}
	
	public static void main(String[] args) {
		ExecutionTime.startTimer();
		for(int i=0 ; i<5000 ; i++) {
			System.out.print(" ");
		}
		System.out.println();
		System.out.println("Execution Time : " + ExecutionTime.endTimer(ExecutionTime.MilliSecondMode));
	}
}

Posted by 황타

티스토리 툴바