aspose file tools*
The moose likes Performance and the fly likes any object better than hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "any object better than hashmap" Watch "any object better than hashmap" New topic
Author

any object better than hashmap

him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
I want to store 2 keys and one value.
I have used hashmap but it's very slow for retrieval of the data as well as in searching of data.
So, can I have a better solution for it.
Please suggest me an efficient one.
Thanks


--Himanshu Jain
http://jainhim.blogspot.com/
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Him,

Could you paste the lookup code? Unless you have some very specific requirements I would say a hashmap should perform just fine. I'm kind'a surprised you find it slow.

Kees Jan


Java-monitor, JVM monitoring made easy <- right here on Java Ranch
him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
i have taken a map and stored my key and value into it.
as, i have 2 keys, so i have taken one more map with parameter as key and a map.
now, i have searched for the key in this map.
It takes more than 25 minutes to search 10,000 keys.
(my map is loaded with 1 million entries).
That's why I am asking for a solution.
Please reply asap.
Thanks
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Him,

Please post your lookup code.

Also, how much memory does your data structure use in memory, what is the heap size you allocated for this JVM?

Does this run in a stand-alone JVM or in an application server?

Kees Jan
him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
Structure of maps:

1st map contains string of size 10 and 2nd is of numeric of 3 digits and value is of 4 characters
Heap size is 75M

Edit: I put code tags around the code to make it sort of readable. Indenting it nicely... too much trouble. -- Paul C
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Him,

What is wrong with this:


him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
it has taken 144s just to query 1000 times.
Please suggest me a better solution or please let me know where I am wrong in my code.
Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

The problem isn't that you have chosen data structures which aren't very efficient. The problem is that you have chosen to use them in an extremely inefficient way. For example this code:

could be replaced by

Essentially you have taken a data structure which provides an access method which is O(1) as its standard access method, and ignored that in favour of writing your own access method which is O(N).
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Him,

Did you try my code?

Also note that 75M is peanuts if your map is 1.000.000 items. How much memory does your map need?

Kees Jan
him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
yes, It worked.
I am extremely grateful to both of you especially Mr. Kees Jan.
I got what you have pointed out.
Thank you very much
It took only 3.5 s to execute 1 million query now.
Kees Jan Koster
JavaMonitor Support
Rancher

Joined: Mar 31, 2009
Posts: 251
    
    5
Dear Him,

That sounds a lot more like a hashmap.

Please check that you are not using more memory than your heap is large. If you use more memory than you have things will also slow down.

Kees Jan
him jain
Ranch Hand

Joined: Feb 05, 2010
Posts: 56
Really sir.
That really now sounds like that.
Thanks for all the info..
[removed email addresses]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: any object better than hashmap