This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Collections Speed Measuring  RSS feed

 
Alexan Kahkejian
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I'am studying the Collection Framework now and I want to do some experiments on the speed of various collections.
So can anyone tell me how can I measure the time taken by a loop (iteration) through a collection.
Thanks in advance
Alexan
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to reinvent the wheel, Alexan. Check out these links:
Collections in Java: Part 1 - The List Interface
Collections in Java: Part 2 - The Set Interface
Storing Objects in Java: Part 3 - The Map Interface
I hope that helps,
Corey
[ June 03, 2003: Message edited by: Corey McGlone ]
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Corey. Yes that does help. And thank you Thomas Paul for the articles.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this topic to the Performance forum as the SCJP exam does not focus on execution speed.
Please continue the discussion there. Thank you
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have a look right in the javadocs. They list the performance of most of the collections and their operations:
here is a sample from the ArrayList docs:
"The size, isEmpty, get, set, iterator, and listIterator operations run in constant time. The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation."
Jamie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!