티스토리 뷰

실행시간 측정하는 3가지 방법 

StopWatch - spring

StopWatch stopWatch = new StopWatch();
stopWatch.start();
//...
//...
//...
stopWatch.stop();
System.out.println("소요시간:"+stopWatch.getTotalTimeMillis()+"ms");
System.out.println(stopWatch.prettyPrint());

* apache comm-lang3에서도 제공되지만 둘다 thread safe 하지 않음 

 

Instant

Instant stime = Instant.now();
//...
//...
//...
Instant etime = Instant.now();
System.out.println("소요시간:"+Duration.between(stime, etime).toMillis()+"ms");

System.currentTimeMillis()

long stime = System.currentTimeMillis();
//...
//...
//...
System.out.println("소요시간:"+(System.currentTimeMillis()-stime)+"ms");

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함