I've been testing the performance of our various Map implementations, and
I've found something strange that I can't explain...

Test class #1)
public static void main(String[] args) {
  Map map = new HashMap();
  map.put("AAA");
  map.put("BBB");
  map.put("CCC");

  long start = 0;
  long end = 0;

  start = System.currentTimeMillis();
  for (int i = RUNS; i >= 0; i--) {
    map.get("AAA");
    map.get("BBB");
    map.get("CCC");
  }
  end = System.currentTimeMillis();
  System.out.println(end - start);
}

Test class #2)
public static void main(String[] args) {
  Map map = new HashMap();
  map.put("AAA");
  map.put("BBB");
  map.put("CCC");

  test(map);
}
private static void test(Map map) {
  long start = 0;
  long end = 0;

  start = System.currentTimeMillis();
  for (int i = RUNS; i >= 0; i--) {
    map.get("AAA");
    map.get("BBB");
    map.get("CCC");
  }
  end = System.currentTimeMillis();
  System.out.println(end - start);
}

These two classes give very different results. The refactored version #2 is
much slower, between 20% and 80% depending on the type of Map.

Am I missing something obvious???
[Sun JDK 1.4.1_01 (client or server)]

Stephen



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to