I am implementing tbb's concurrent hash map to compare the performance of it against a suite of other concurrent hash tables.
However the performance I get out of it is horrendous, I just can't believe it is that slow compared to other concurrent hash tables
Here is my implementation of it:
class TBB: public TestDs{
typedef tbb::concurrent_hash_map<int,int, HashCompare<int> > hash_t;
private:
hash_t _ds;
public:
TBB(const Configuration& config) : _ds(config.initial_count) {
}
bool containsKey(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return true;
}
else
return false;
}
int get(int key) {
hash_t::accessor a;
if(_ds.find(a,key)){
return (int)(a->second);
}
else
return 0;
}
int put(int key, int value) {
return _ds.insert( std::make_pair(key, value) );
}
int remove(int key) {
return _ds.erase(key);
}
int size() {
return _ds.size();
}
const char* name() {
return "TBB";
}
void print() {}
void shutdown() {}
};
Does anyone see any issue with my implementation or know of any reason why it may perform slow? It takes over 30 mins for it to insert 200,000 elements in a single thread environment. To put that in perspective, nearly all the other tables perform this test in less than 5 mins.
Here is my build code:
-w -DNDEBUG -g -msse2 -m32 -DINTEL -D_REENTRANT -lrt -pthread -fno-strict-aliasing -l cds -l tbb -lllalloc
UPDATE: I have adjusted my testing code to prefill the hash tables to 1000, instead of 100,000. When running it again, tbb performs 92 op/sec while, another implementation performs 89431 op/sec. (64 thread environment)...Just saying something doesn't seem right....
Additional Info: Computer is a HP Z600 Workstation with 6gb of ram and 6 cores.
Notice Cross positing at : http://software.intel.com/en-us/forums/showthread.php?t=86119
You HashCompare::hash()
returns sizeof(int)
, which, I guess, means every entry maps into the same bucket. It seems like you are not using it as a hash table, more of a linked list.
You could try using Boost's hash:
#include <boost/functional/hash.hpp>
template<typename K>
struct HashCompare {
static size_t hash( const K& key ) { return boost::hash_value(key); }
static bool equal( const K& key1, const K& key2 ) { return ( key1 == key2 ); }
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With