System클래스에 static native 메서드로 currentTimeMillis()가 정의되어 있다.
currentTimeMillis() 메서드를 사용해서 프로그램의 성능을 테스트할 수 있다.
public static void main(String[] args) {
long start = 0, end = 0;
double result = 0;
start = System.currentTimeMillis();
// 실행코드 작성
// 종료
end = (System.currentTimeMillis() - start);
result = end / 1000.0;
System.out.printf("소요시간 : %.6f초 %n", result);
}
주석 안에 코드를 작성하면 소요시간을 소수점 6자리까지 잘라서 보여준다.
'Java' 카테고리의 다른 글
getClass() (0) | 2023.06.09 |
---|---|
clone 메서드의 문제점 (얕은 복사, 깊은 복사) (0) | 2023.06.07 |
String Class의 특징 (0) | 2023.06.05 |
Object class의 메서드 (0) | 2023.05.30 |
Chained Exception (0) | 2023.05.29 |