Conclusions
Inserting & Reading sequentially from Collection prefer LinkedList/ArrayList
Inserting & Reading/Deleting by Search/equals from Collection prefer HashSet
Inserting, ArrayList & LinkedList performs best while HashSet takes double the time
Reading, HashSet performs best while ArrayList & LinkedList are marginally less
Deleting, HashSet performs 10 times better than ArrayList & ArrayList performs 4 times better than LinkedList. LinkedList is slow because of sequencial search
Bottom line : unless you are not going to iterate using for(Integer i : list ) then prefer HashSet
Inserting/Reading/Deleting integer's from zero till count
JDK7 | Collection | action | count | time ms |
---|---|---|---|---|
ArrayList | Insert | 100 | 0/1 | |
LinkedList | Insert | 100 | 0/1 | |
HashSet | Insert | 100 | 0/1 | |
ArrayList | Insert | 10000 | 5 | |
LinkedList | Insert | 10000 | 4 | |
HashSet | Insert | 10000 | 7 | |
ArrayList | Insert | 100000 | 11 | |
LinkedList | Insert | 100000 | 11 | |
HashSet | Insert | 100000 | 21 | |
ArrayList | Get/Read | 100 | 0 | |
LinkedList | Get/Read | 100 | 0 | |
HashSet | Get/Read | 100 | 0 | |
ArrayList | Get/Read | 10000 | 4 | |
LinkedList | Get/Read | 10000 | 3 | |
HashSet | Get/Read | 10000 | 4 | |
ArrayList | Get/Read | 100000 | 10 | |
LinkedList | Get/Read | 100000 | 10 | |
HashSet | Get/Read | 100000 | 9 |
JDK6 | Collection | action | count | time ms |
---|---|---|---|---|
ArrayList | Insert | 100 | 0/1 | |
LinkedList | Insert | 100 | 0/1 | |
HashSet | Insert | 100 | 0/1 | |
ArrayList | Insert | 10000 | 5 | |
LinkedList | Insert | 10000 | 4 | |
HashSet | Insert | 10000 | 7 | |
ArrayList | Insert | 100000 | 12 | |
LinkedList | Insert | 100000 | 11 | |
HashSet | Insert | 100000 | 17 | |
ArrayList | Get/Read | 100 | 0 | |
LinkedList | Get/Read | 100 | 0 | |
HashSet | Get/Read | 100 | 0 | |
ArrayList | Get/Read | 10000 | 5 | |
LinkedList | Get/Read | 10000 | 3 | |
HashSet | Get/Read | 10000 | 4 | |
ArrayList | Get/Read | 100000 | 10 | |
LinkedList | Get/Read | 100000 | 10 | |
HashSet | Get/Read | 100000 | 9 |
JDK6 | Collection | action | count | time ms |
---|---|---|---|---|
ArrayList | insert & remove 25% | 100000 | 336 | |
LinkedList | Get/Read | 100000 | 1188 | |
HashSet | Get/Read | 100000 | 25 |
JDK7 | Collection | action | count | time ms |
---|---|---|---|---|
ArrayList | insert & remove 25% | 100000 | 337 | |
LinkedList | Get/Read | 100000 | 1208 | |
HashSet | Get/Read | 100000 | 32 |
Environment
MacBook Pro
Processor 2.3 GHz Intel Core i7
Memory 16 GB 1600 MHz DDR3
Software OS X 10.8 (12A269)
Comments