Skip to main content

Posts

Showing posts from August, 2012

ArrayList vs LinkedList vs HashSet Performance Comparision

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 LinkedLis