sparse_hash_map<int, double> very slow

77 views
Skip to first unread message

ben...@gmail.com

unread,
Feb 2, 2016, 9:02:38 AM2/2/16
to google-sparsehash
Hi all,

I am trying to use the sparse_hash_map with int as keys and double as values, but it is really slow.
It takes about 34 secs to store an image (only the non-zero values) vs 2 secs when using unordered_map.
I'm using the following code:


  sparse_hash_map<int, double> himg;
  himg
.set_deleted_key(-1);

   
for (int idx = 0; idx < numvoxels; ++idx) {
        val
=image->Get(idx);
       
if(val){
            himg
[idx]=val;
       
}
   
}

What could be causing this performance?

Thank you!
Antonis

Geoff Pike

unread,
Feb 4, 2016, 3:42:42 PM2/4/16
to google-s...@googlegroups.com
sparse_hash_map is slower than most hash-based maps, especially for
inserting. You may be better off using a different data structure.
When the keys are clumpy (as they probably are in your case, since I
bet image->Get(idx) is correlated with image->Get(idx+1)), a trie
might be worthwhile.

Geoff
Reply all
Reply to author
Forward
0 new messages