Findbugs-discuss

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Findbugs-discuss

by Sam Beroz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I've gotten several WMI_WRONG_MAP_ITERATOR warnings complaining that iterating over the keySet and calling get() for each key is inefficient when compared to iterating over the entrySet() for both keys and values.  I've tried testing this using Sun's 6u13 jdk and no matter what I try iterating over the keySet and calling get is almost always faster.  What am I doing wrong?  Can you point me to an example or some sort of explaination behind this bug pattern?  Thanks - Sam



     
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Re: Findbugs-discuss

by Dave Brosius-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The keyset iterator is just a decorator on top of the entryset iterator, as a map is just a set of entries. Perhaps 1.6 just returns the value from the key, instead of doing the lookup, which would mean it is as fast as the entryset iterator. I can't explain your findings.

-----Original Message-----
From: "Sam Beroz" <samberoz@...>
Sent: Thursday, July 30, 2009 9:05pm
To: findbugs-discuss@...
Subject: [FB-Discuss] Findbugs-discuss


I've gotten several WMI_WRONG_MAP_ITERATOR warnings complaining that iterating over the keySet and calling get() for each key is inefficient when compared to iterating over the entrySet() for both keys and values. I've tried testing this using Sun's 6u13 jdk and no matter what I try iterating over the keySet and calling get is almost always faster. What am I doing wrong? Can you point me to an example or some sort of explaination behind this bug pattern? Thanks - Sam




_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss

Parent Message unknown Re: Findbugs-discuss

by Sam Beroz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I think I figured out what I was doing wrong.  In an attempt to get more consistent timing numbers I was looping over the map iterations:

        for (int i = 0; i < NUM_TESTS; i++)
            for (Integer key : map1.keySet()) {
                sum += key.intValue() + map1.get(key).intValue();
           
The outer loop is masking the timing difference to initially set up the decorator.  Removing the outer loop make the difference consistently visible.  Thanks for the help. - Sam


Message: 4
Date: Thu, 30 Jul 2009 23:14:55 -0400 (EDT)
From: "Dave Brosius" <dbrosius@...>
Subject: Re: [FB-Discuss] Findbugs-discuss
To: "Sam Beroz" <samberoz@...>
Cc: findbugs-discuss@...
Message-ID: <1249010095.824610999@...>
Content-Type: text/plain; charset="utf-8"

The keyset iterator is just a decorator on top of the entryset iterator, as a map is just a set of entries. Perhaps 1.6 just returns the value from the key, instead of doing the lookup, which would mean it is as fast as the entryset iterator. I can't explain your findings.

-----Original Message-----
From: "Sam Beroz" <samberoz@...>
Sent: Thursday, July 30, 2009 9:05pm
To: findbugs-discuss@...
Subject: [FB-Discuss] Findbugs-discuss


I've gotten several WMI_WRONG_MAP_ITERATOR warnings complaining that iterating over the keySet and calling get() for each key is inefficient when compared to iterating over the entrySet() for both keys and values.  I've tried testing this using Sun's 6u13 jdk and no matter what I try iterating over the keySet and calling get is almost always faster.  What am I doing wrong?  Can you point me to an example or some sort of explaination behind this bug pattern?  Thanks - Sam


     
_______________________________________________
Findbugs-discuss mailing list
Findbugs-discuss@...
https://mailman.cs.umd.edu/mailman/listinfo/findbugs-discuss