속도체크

2,599 views

Published on

Published in: Business, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,599
On SlideShare
0
From Embeds
0
Number of Embeds
1,612
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

속도체크

  1. 1. Java, 특정 로직에 대한 성능 확인(속도 체크)<br />김용환<br />
  2. 2. System.currentTimeMillis()<br />소스<br />long startTime = System.currentTimeMillis();Thread.sleep(1000);long estimatedTime = System.currentTimeMillis() - startTime;System.out.println("took " + estimatedTime + " ms");<br />결과<br />took 1000 ms<br />
  3. 3. System.nanoTime() <br />소스<br />long time1 = System.nanoTime();Thread.sleep(1000);long time2 = System.nanoTime();long timeSpent = time2 - time1;System.out.println("took " + timeSpent + " ns");<br />결과<br />took 1000232514 ns<br />
  4. 4. Commons-lang의 StopWatch (2.3)<br />import org.apache.commons.lang.time.StopWatch;..StopWatchstopWatch = new StopWatch();stopWatch.reset();stopWatch.start();Thread.sleep(2000);stopWatch.stop();System.out.println(stopWatch.toString());  stopWatch.reset();stopWatch.start();Thread.sleep(5000);stopWatch.stop();System.out.println(stopWatch.toString());  stopWatch.reset();stopWatch.start();Thread.sleep(3000);stopWatch.stop();System.out.println(stopWatch.toString());<br />소스<br />0:00:02.0000:00:05.0000:00:03.000<br />결과<br />
  5. 5. Spring core lib에 있는 util성 StopWatch (3.0)<br />소스<br />import org.springframework.util.StopWatch;...StopWatchstopWatch = new StopWatch("Stop Watch");stopWatch.start("initializing");Thread.sleep(2000);stopWatch.stop();System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");<br />stopWatch.start("processing");Thread.sleep(5000);stopWatch.stop();System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");  stopWatch.start("finalizing");Thread.sleep(3000);stopWatch.stop();System.out.println("took " + stopWatch.getLastTaskTimeMillis() + " ms");  System.out.println(stopWatch.toString());System.out.println();System.out.println(stopWatch.prettyPrint());<br />
  6. 6. Spring core lib에 있는 util성 StopWatch (3.0)<br />결과<br />took 2000 mstook 5000 mstook 3001 msStopWatch 'Stop Watch': running time (millis) = 10001; [initializing] took 2000 = 20%; [processing] took 5000 = 50%; [finalizing] took 3001 = 30%<br />StopWatch 'Stop Watch': running time (millis) = 10001-----------------------------------------ms     %     Task name-----------------------------------------02000  020%  initializing05000  050%  processing03001  030%  finalizing<br />
  7. 7. 남의 것 사용<br />그냥 인터넷에서 남들이 만든 StopWatch를 찾아서 copy&paste한다.http://www.devdaily.com/blog/post/java/stopwatch-class-that-can-be-used-for-timings-benchmarks<br />
  8. 8. Commons-lang의 StopWatch와 Spring Util의 StopWatch비교<br />

×