Re: Hashtable-based word count performance

Discussion in 'Java' started by William Brogden, Jul 29, 2003.

  1. "enclume42" <> wrote in message
    news:...
    > Hi everybody,
    >
    > I am doing a (kind of) word count procedure in a Java
    > program. The point is that my method is awfully slow
    > (several tens of seconds to bin about 40'000 words on
    > a decently powerful machine).
    >
    > I suspect the following lines to be the cause of this
    > poor performance, because of object creation/loss-of-reference/
    > garbage-collector-overheating:
    >
    > if (!ugcounter.containsKey(ug)) {
    > ugcounter.put(ug,new Integer(1));
    > } else {
    > ugcounter.put(ug,new

    Integer(1+((Integer)ugcounter.get(ug)).intValue()));
    > }
    >
    > (ugcounter is a Hashtable and ug is a String, and my "vocabulary"
    > contains about 10'000 different words)
    >
    > Do you have any suggestion to improve this piece of code ?


    How about an int[] of size 1 for the stored object? that way you don't have
    all the object creation overhead.
    WBB




    ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
     
    William Brogden, Jul 29, 2003
    #1
    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:
    644
    Roedy Green
    Jul 29, 2003
  2. Roedy Green
    Replies:
    2
    Views:
    669
    Roedy Green
    Aug 2, 2003
  3. zer0frequency
    Replies:
    2
    Views:
    774
    andrewh1
    Jul 10, 2004
  4. Kevin
    Replies:
    16
    Views:
    8,381
    Dale King
    Apr 19, 2005
  5. efelnavarro09
    Replies:
    2
    Views:
    977
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page