File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Performance and the fly likes Collections Speed Measuring Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Performance
Reply Bookmark "Collections Speed Measuring" Watch "Collections Speed Measuring" New topic
Author

Collections Speed Measuring

Alexan Kahkejian
Ranch Hand

Joined: Apr 30, 2003
Posts: 74
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


Alexan Kahkejian<br />SCJP<br />SCWCD<br /><a href="http://www.javaemployer.com" target="_blank" rel="nofollow">http://www.javaemployer.com</a>
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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 ]

SCJP Tipline, etc.
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Thank you Corey. Yes that does help. And thank you Thomas Paul for the articles.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

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
 
 
subject: Collections Speed Measuring
 
Threads others viewed
Collection, Collections, Java Collections Framework
With JPA how can I force loading of nested lazy collections?
help me please to choose the best
Collections and Generics
diff between collection and colletions frame works
MyEclipse, The Clear Choice