Diff for "CalendarIsTooSlow"

Differences between revisions 2 and 0

Deletions are marked like this. Additions are marked like this.
Line 97: Line 97:
 [http://reckless.greatnow.com/89.html webcam software freeware] | [http://kishinev.g0g.net/39.html adult webcam post] | [http://spirits.9cy.com/58.html sloppy creampie] | [http://parlays.150m.com/21.html female domination wrestling] | [http://squealer.741.com/64.html femdom kicking] | [http://abatement.fcpages.com/52.html college dirty blonde] | [http://mudrooms.dreamstation.com/8.html teenager male sex] | [http://leafstalks.741.com/77.html fem dom bitches] | [http://zeroed.9cy.com/23.html pink dildo] | [http://rotations.angelcities.com/92.html anal fucking wives] | [http://homepage.mac.com/contemn/78.html free webcam boys] | [http://matings.o-f.com/22.html male webcams] | [http://careering.exactpages.com/36.html female double penetration] | [http://homepage.mac.com/ammeter/5.html movies webcam swinger] | [http://homepage.mac.com/lifeblood/52.html streaming airport webcam] | [http://trooped.envy.nu/2.html futurama hentai clip] | [http://randy.fcpages.com/79.html senior porno] | [http://emotional.o-f.com/81.html trampling torture] | [http://typist.dreamstation.com/82.html cock opn webcam] | [http://ranters.dreamstation.com/93.html anal gape pics] | [http://miswrite.wtcsites.com/8.html webcam girls dorm] | [http://homepage.mac.com/woodcraft1/28.html girls msn webcam] | [http://homepage.mac.com/yarmulkes/61.html webcam pics girls] | [http://bullwhip.dreamstation.com/52.html princess sex webcam] | [http://rummer.dreamstation.com/28.html gang blow job] | [http://yap.freecities.com/68.html group sex gay] | [http://homepage.mac.com/marylander1/78.html webcam live girl] | [http://av.dreamstation.com/16.html preggo shaved] | [http://backhoe.wtcsites.com/2.html creative webcam monitor] | [http://pinocles.dreamstation.com/91.html mature fist fucking] | [http://tapelines.kogaryu.com/90.html black hardcore party] | [http://adagios.150m.com/69.html mature lesbos pussy] | [http://homepage.mac.com/brokered/64.html under 18 webcam] | [http://bribes.freewebpages.org/27.html daughter webcam] | [http://hightail.exactpages.com/71.html alt sex erotic] | [http://homepage.mac.com/permafrost2/58.html bored housewives webcams] | [http://enchanted.dreamstation.com/56.html mom team gangbang] | [http://alibiing.741.com/ guys bare butt] | [http://tintypes.bravepages.com/29.html oral history job]

java.util.Calendar 객체를 생성하는 데는 상당한 비용이 소요된다.

즉,

  • Calendar.getInstance()

라는 메소드를 호출하여 Calendar 객체를 가져오는 데 걸리는 시간이 상당하다.

   1     // 현재 시간을 가져오는 보통의 방법
   2     private static Calendar getCalendar1() {
   3         return Calendar.getInstance();
   4     }
   5 
   6     // 현재 시간은 아니지만 Calendar 객체를 clone을 통해 가져오는 방법
   7     private static Calendar getCalendar2() {
   8         return (Calendar) cal.clone();
   9     }
  10 
  11     // Calendar 객체를 clone을 통해 가져와서 현재 시간으로 만드는 방법
  12     private static Calendar getCalendar3() {
  13         Calendar c = (Calendar) cal.clone();
  14         c.setTimeInMillis(System.currentTimeMillis());
  15         return c;
  16     }
  17 
  18     // 가장 범용적인 GregorianCalendar 객체를 직접 생성하는 방법
  19     private static Calendar getCalendar4() {
  20         Calendar c = new GregorianCalendar();
  21         return c;
  22     }

위의 메소드를 약 10만회씩 실행한 결과는 다음과 같다.

   1 // JDK 1.4
   2 
   3 it took 391 (ms)
   4 it took 187 (ms)
   5 it took 375 (ms)
   6 it took 328 (ms)
   7 
   8 // JDK 1.5
   9 
  10 it took 469 (ms)
  11 it took 266 (ms)
  12 it took 421 (ms)
  13 it took 344 (ms)

JDK 1.4와 1.5 모두 그냥 Calendar 객체를 clone을 통해 만드는 것이 가장 빨랐다. Calendar.getInstance()에 비해 거의 두 배가 빠르다.

따라서 단순히 Calendar 객체가 필요하고 여기에 시간을 다시 지정해야 할 것이라면 clone 방법을 사용하는 것이 가장 좋다.

그럼 만약 현재 시간의 Calendar 객체가 필요하다면?

GregorianCalendar를 사용하지 않는 환경에서는 호환성이 문제가 되겠지만 대부분의 지역에서는 직접 new GregorianCalendar()를 사용하는 것이 가장 효율적이다.

그럼 Calendar 객체간의 시간 비교는 어떨까?

다음 테스트는 Calendar 객체와 현재 시간과의 비교이다. 현재 시간이 아닌 경우에는 결과가 많이 다를 수 있다. 그 이유는 Calendar.getInstance()가 new Date()에 비해 훨씬 비싸기 때문이다. 그리고 new Date() 객체 역시 System.currentTimeMillis()에 비해 매우 비싸다.

   1     // 현재 시간과 비교할 때 new Date()와 비교
   2     private static boolean compareCalendar1(Calendar cal) {
   3         return cal.getTime().after(new Date());
   4     }
   5 
   6     // 현재 시간과 비교할 때 Calendar.getInstance()와 비교
   7     private static boolean compareCalendar2(Calendar cal) {
   8         return cal.after(Calendar.getInstance());
   9     }
  10 
  11     // 현재 시간과 비교할 때 System.currentTimeMillis()와 비교
  12     private static boolean compareCalendar3(Calendar cal) {
  13         return cal.getTimeInMillis() > System.currentTimeMillis();
  14     }
  15 

역시 10만번 수행 결과는 다음과 같다.

   1 
   2 // JDK 1.4
   3 
   4 compare1 took 110 (ms)
   5 compare2 took 328 (ms)
   6 compare3 took 15 (ms)
   7 
   8 // JDK 1.5
   9 
  10 compare1 took 78 (ms)
  11 compare2 took 360 (ms)
  12 compare3 took 15 (ms)

last edited 2007-11-24 12:04:33 by YoonKyungKoo