Re: Hashtable-based word count performance

Discussion in 'Java' started by Roedy Green, Jul 29, 2003.

  1. Roedy Green

    Roedy Green Guest

    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, Jul 29, 2003
    #1
    1. Advertising

  2. 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, Jul 30, 2003
    #2
    1. Advertising

  3. Roedy Green

    Roedy Green Guest

    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, Aug 2, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordon Beaton
    Replies:
    3
    Views:
    633
    Roedy Green
    Jul 29, 2003
  2. William Brogden

    Re: Hashtable-based word count performance

    William Brogden, Jul 29, 2003, in forum: Java
    Replies:
    0
    Views:
    538
    William Brogden
    Jul 29, 2003
  3. zer0frequency
    Replies:
    2
    Views:
    750
    andrewh1
    Jul 10, 2004
  4. Kevin
    Replies:
    16
    Views:
    8,251
    Dale King
    Apr 19, 2005
  5. efelnavarro09
    Replies:
    2
    Views:
    939
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page