DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Data
  4. Comparing Collections speeds

Comparing Collections speeds

Peter Lawrey user avatar by
Peter Lawrey
·
Aug. 08, 11 · Interview
Like (0)
Save
Tweet
Share
7.75K Views

Join the DZone community and get the full member experience.

Join For Free

The speed of different collections tends to depend on their usage pattern however it can be useful to have an idea of their relative performance.

The test

In this test I compare both single thread and thread safe collections of different sizes.

Adding is from lowest to highest values. Removal is from start and end, finishing with the middle value. This disadvantages ArrayList and LinkedList relatively equally.

CollectionSizeAddingIteratingRemoving
ArrayList100,00030.114.567,359
ArrayList10,0008.311.26,323
ArrayList1,0006.49.4585
ArrayList1006.89.592.9
ArrayList109.713.236.6
LinkedList100,00046.441.4139,326
LinkedList10,0009.330.313,413
LinkedList1,0008.727.61,025
LinkedList1007.819.8110
LinkedList1011.230.338.7
HashSet100,00028.611569.5
HashSet10,00025.732458.6
HashSet1,00026.02,52159.2
HashSet10030.024,49064.6
HashSet1051.7244,045131
LinkedHashSet100,00035.910369.2
LinkedHashSet10,00030.310165.0
LinkedHashSet1,00029.210065.8
LinkedHashSet10031.598.860.6
LinkedHashSet1045.411069.8
TreeSet100,000159106187
TreeSet10,00099.677.6111
TreeSet1,00078.557.593.7
TreeSet10054.047.983.7
TreeSet1030.251.049.4
newSetFromMap IdentityHashMap100,00074.1216153
newSetFromMap IdentityHashMap10,00065.5370126
newSetFromMap IdentityHashMap1,00060.41,644115
newSetFromMap IdentityHashMap10021.114,21648.9
newSetFromMap IdentityHashMap1046.7140,162109
newSetFromMap WeakHashMap100,00052.414887.4
newSetFromMap WeakHashMap10,00033.521771.2
newSetFromMap WeakHashMap1,00032.91,08872.2
newSetFromMap WeakHashMap10032.19,71764.3
newSetFromMap WeakHashMap1048.098,76993.0
Thread Safe Collections
synchronized ArrayList100,00022.610198,735
synchronized ArrayList10,00012.110110,084
synchronized ArrayList1,00011.599.51,023
synchronized ArrayList10011.4101144
synchronized ArrayList1014.011154.0
Vector100,00023.929864,333
Vector10,00020.43725,919
Vector1,00019.4372612
Vector10019.3375145
Vector1022.939797.5
synchronized LinkedList100,00037.6100132,660
synchronized LinkedList10,00019.299.613,049
synchronized LinkedList1,00022.299.11,005
synchronized LinkedList10023.7102134
synchronized LinkedList1026.111562.6
synchronized HashSet100,00050.113895.7
synchronized HashSet10,00043.034793.1
synchronized HashSet1,00042.72,55595.3
synchronized HashSet10047.024,60897.4
synchronized HashSet1085.7245,343204
synchronized LinkedHashSet100,00048.610393.1
synchronized LinkedHashSet10,00045.610188.1
synchronized LinkedHashSet1,00048.710694.6
synchronized LinkedHashSet10048.110186.8
synchronized LinkedHashSet1057.811493.4
synchronized TreeSet100,000116105179
synchronized TreeSet10,00074.175.4122
synchronized TreeSet1,00063.553.9103
synchronized TreeSet10050.846.290.4
synchronized TreeSet1029.149.157.6
CopyOnWriteArrayList100,00035,35465.8165,197
CopyOnWriteArrayList10,0002,11597.736,269
CopyOnWriteArrayList1,00021775.11,828
CopyOnWriteArrayList10060.063.4227
CopyOnWriteArrayList1048.271.0103
CopyOnWriteArraySet100,000106,11663.3165,708
CopyOnWriteArraySet10,00028,73691.229,820
CopyOnWriteArraySet1,0001,14375.11,852
CopyOnWriteArraySet10013463.4233
CopyOnWriteArraySet1055.373.0109
newSetFromMap ConcurrentHashMap100,00070.6291149
newSetFromMap ConcurrentHashMap10,00057.2485120
newSetFromMap ConcurrentHashMap1,00053.42,869121
newSetFromMap ConcurrentHashMap10054.724,150140
newSetFromMap ConcurrentHashMap1068.793,921197
newSetFromMap ConcurrentSkipListMap100,00013596.8365
newSetFromMap ConcurrentSkipListMap10,00011395.1285
newSetFromMap ConcurrentSkipListMap1,00097.894.7234
newSetFromMap ConcurrentSkipListMap10083.395.2192
newSetFromMap ConcurrentSkipListMap1064.2112151

The code

AddIterateRemoveTest.java
Timings are in nano-seconds per element.

Related Article

Collections Library for millions of elements

 

From http://vanillajava.blogspot.com/2011/08/comparing-collections-speeds.html

Data structure

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Introduction to Containerization
  • Introduction to Container Orchestration
  • Stop Using Spring Profiles Per Environment
  • Building Microservice in Golang

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: