Collections performance

C

Chris

Does anyone know of a good benchmark of HashMap, TreeMap, and maybe some
other alternatives like Trove?

I need to add items to a map, and then get them out in sorted order, and
I'm wondering if it it's faster to use a HashMap, copy to an array, and
then sort, or just use a TreeMap.
 
S

Steve W. Jackson

Chris said:
Does anyone know of a good benchmark of HashMap, TreeMap, and maybe some
other alternatives like Trove?

I need to add items to a map, and then get them out in sorted order, and
I'm wondering if it it's faster to use a HashMap, copy to an array, and
then sort, or just use a TreeMap.

I don't know of any benchmarks and never heard of Trove. But I can tell
you that, having made extensive use of Java's Collections, they perform
quite well. (And see the Javadocs for some performance information.)

As to whether to use a HashMap or TreeMap, I'd say it would depend on
just how often you need the entire set of data in the sorted order of
your keys. If it's seldom, and the data set isn't exceedingly large, I
suppose it *could* make sense to get all the keys and iterate over them
in sorted order. If you need to iterate over the entire set frequently,
then the TreeMap is likely to be better. Without more information, it's
even possible that neither of these would be your ideal choice...it all
depends on what you need to accomplish.

= Steve =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top