비로소 더 정확한 알고리즘의 수행속도 Check가 가능하다.
다음은 샘플이지만 결국 간단하게 사용할 수 밖에 없을 것이다.
static의 클래스레벨의 속성 때문에 여러군데에서 동시에 벤치마크를 수행할 수 없다.
하지만 간단한 수행시간 체크정도는 수행할 것이다.
package kr.ac.kyungnam.dblab;
public class Benchmark {
/**
* The field that has starting time
*/
private static long startTime = 0;
/**
* The field that has ending time
*/
private static long endTime = 0;
/**
* The method that set the starting time
*/
public static void start() {
//startTime = System.currentTimeMillis();
startTime = System.nanoTime();
}
/**
* The method that set the finishing time
*/
public static void finish() {
//endTime = System.currentTimeMillis();
endTime = System.nanoTime();
}
/**
* the difference between endtime and starttime
* @return
* return nano second time
*/
public static long result() {
return endTime - startTime;
}
}
