![]() |
|
|
|||||||
![]() |
Java - Re: Hashtable-based word count performance |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
On 28 Jul 2003 12:06:46 -0700, (enclume42) wrote
or quoted : > Do you have any suggestion to improve this piece of code ? Why not store a MUTABLE integer object. e.g. a object with a single public int field. You can then update it with ++ instead of all that unboxing/boxing crud. You are needless creating thousands of little objects you soon discard. You might try another sort of algorithm. Sort the data and count dups. Try using a Hashtable and choosing the initial size to be a fat prime. That saves lots of chain chasing. It won't work with HashMap which rounds off to powers of two. See http://mindprod.com/jgloss/hashtable.html -- Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary. Roedy Green |
|
|
|
|
#2 |
|
Posts: n/a
|
Hi.
Powers of two or not. Seems to me that the unsychronized Hashmap should still be faster for this purpose. Hashtables deals with multithreaded updates, and are therefore synchronized. That might take a lot of time. - Jens Roedy Green wrote: > On 28 Jul 2003 12:06:46 -0700, (enclume42) wrote > or quoted : > > >> Do you have any suggestion to improve this piece of code ? > > > Why not store a MUTABLE integer object. e.g. a object with a single > public int field. You can then update it with ++ instead of all that > unboxing/boxing crud. You are needless creating thousands of little > objects you soon discard. > > You might try another sort of algorithm. Sort the data and count > dups. > > Try using a Hashtable and choosing the initial size to be a fat prime. > That saves lots of chain chasing. It won't work with HashMap which > rounds off to powers of two. See > http://mindprod.com/jgloss/hashtable.html > > -- > Canadian Mind Products, Roedy Green. > Coaching, problem solving, economical contract programming. > See http://mindprod.com/jgloss/jgloss.html for The Java Glossary. Jens Andersen |
|
|
|
#3 |
|
Posts: n/a
|
On Wed, 30 Jul 2003 15:36:15 +0200, Jens Andersen <> wrote or
quoted : >Powers of two or not. Seems to me that the unsychronized Hashmap should >still be faster for this purpose. The nice thing about Collections it is quite easy to make experiments like that to find out which is quicker in any given JVM. See http://mindprod.com/jgloss/tweakable.html -- Canadian Mind Products, Roedy Green. Coaching, problem solving, economical contract programming. See http://mindprod.com/jgloss/jgloss.html for The Java Glossary. Roedy Green |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Best CPU Cooler Performance LGA1366 Q2-2009 | Admin | Front Page News | 0 | 08-05-2009 04:56 PM |
| Performance Based testing | Darrilgibson@gmail.com | MCITP | 0 | 08-03-2008 01:09 PM |