간단 성능 테스트 코드
long time = System.currentTimeMillis();
reportPerformanceFor("starting at", time);
className.Method() //테스트하려는 함수 호출
reportPerformanceFor("graph allocation", time);
reportPerformanceFor("graph allocation", time);
System.out.println("\n" + "Paused: graph is still in memory (to check mem consumption).");
System.out.print("press enter to free memory and finish...");
System.out.print("press enter to free memory and finish...");
try {
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.in.read();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("done.");
private static void reportPerformanceFor(String msg, long refTime)
{
double time = (System.currentTimeMillis() - refTime) / 1000.0;
double mem = usedMemory()
/ (1024.0 * 1024.0);
mem = Math.round(mem * 100) / 100.0;
System.out.println(msg + " (" + time + " sec, " + mem + "MB)");
}
private static void reportPerformanceFor(String msg, long refTime)
{
double time = (System.currentTimeMillis() - refTime) / 1000.0;
double mem = usedMemory()
/ (1024.0 * 1024.0);
mem = Math.round(mem * 100) / 100.0;
System.out.println(msg + " (" + time + " sec, " + mem + "MB)");
}
private static long usedMemory()
{
Runtime rt = Runtime.getRuntime();
{
Runtime rt = Runtime.getRuntime();
return rt.totalMemory() - rt.freeMemory();
}
}
'프로그래밍 > Java' 카테고리의 다른 글
[Java] Scanner (0) | 2011.06.05 |
---|---|
[Java] 인스턴스 변수 와 지역변수의 차이점 (0) | 2011.02.28 |
[Java] 오버로딩, 오버라이딩 ( Overloading, Overriding ) (0) | 2011.02.21 |
[이클립스] 이클립스 UTF-8 설정 (0) | 2011.02.01 |
자바 연산자 우선순위 (0) | 2009.05.16 |