Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - Re: Hashtable-based word count performance

 
Thread Tools Search this Thread
Old 07-29-2003, 01:00 AM   #1
Default Re: Hashtable-based word count performance


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
  Reply With Quote
Old 07-30-2003, 02:36 PM   #2
Jens Andersen
 
Posts: n/a
Default Re: Hashtable-based word count performance
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
  Reply With Quote
Old 08-02-2003, 10:47 PM   #3
Roedy Green
 
Posts: n/a
Default Re: Hashtable-based word count performance
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46