Perhaps in the first test, the VM knows that the map is a HashMap, and skips
the virtual method calls and calls HashMap directly. Try redefining the test
method to accept a HashMap and see what happens.
----- Original Message -----
From: "Stephen Colebourne" <[EMAIL PROTECTED]>
To: "Jakarta Commons Developers List" <[EMAIL PROTECTED]>
Sent: Sunday, January 19, 2003 08:33 AM
Subject: [general] Performance testing oddity
> 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]>
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>