2011-12-12 10:05:35 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <vector>
|
|
|
|
|
2014-01-08 16:33:28 +00:00
|
|
|
#include <unordered_map>
|
2011-12-12 10:05:35 +00:00
|
|
|
|
2013-04-09 19:15:52 +00:00
|
|
|
#include <sparsehash/dense_hash_map>
|
|
|
|
#include <sparsehash/sparse_hash_map>
|
2011-12-19 02:00:40 +00:00
|
|
|
|
|
|
|
#include <statdaemons/Stopwatch.h>
|
|
|
|
|
2012-06-01 10:45:29 +00:00
|
|
|
#define DBMS_HASH_MAP_COUNT_COLLISIONS
|
|
|
|
|
2011-12-19 02:00:40 +00:00
|
|
|
#include <DB/Core/Types.h>
|
2012-06-01 10:45:29 +00:00
|
|
|
#include <DB/IO/ReadBufferFromFile.h>
|
|
|
|
#include <DB/IO/CompressedReadBuffer.h>
|
2014-04-28 01:48:24 +00:00
|
|
|
#include <DB/Common/HashTable/HashMap.h>
|
2011-12-12 10:05:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv)
|
|
|
|
{
|
2012-06-01 10:45:29 +00:00
|
|
|
typedef DB::UInt64 Key;
|
|
|
|
typedef DB::UInt64 Value;
|
|
|
|
|
|
|
|
size_t n = atoi(argv[1]);
|
|
|
|
//size_t m = atoi(argv[2]);
|
2011-12-19 02:00:40 +00:00
|
|
|
|
|
|
|
std::vector<Key> data(n);
|
|
|
|
|
|
|
|
std::cerr << "sizeof(Key) = " << sizeof(Key) << ", sizeof(Value) = " << sizeof(Value) << std::endl;
|
|
|
|
|
|
|
|
{
|
2012-06-01 10:45:29 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
DB::ReadBufferFromFile in1("UniqID.bin");
|
|
|
|
DB::CompressedReadBuffer in2(in1);
|
|
|
|
|
|
|
|
in2.readStrict(reinterpret_cast<char*>(&data[0]), sizeof(data[0]) * n);
|
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
|
|
|
<< "Vector. Size: " << n
|
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2011-12-12 10:05:35 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Stopwatch watch;
|
2011-12-19 02:00:40 +00:00
|
|
|
|
2014-04-28 01:48:24 +00:00
|
|
|
HashMap<Key, Value> map;
|
|
|
|
HashMap<Key, Value>::iterator it;
|
2011-12-19 02:00:40 +00:00
|
|
|
bool inserted;
|
|
|
|
|
|
|
|
for (size_t i = 0; i < n; ++i)
|
2011-12-12 10:05:35 +00:00
|
|
|
{
|
2011-12-19 02:00:40 +00:00
|
|
|
map.emplace(data[i], it, inserted);
|
|
|
|
if (inserted)
|
2012-06-01 10:45:29 +00:00
|
|
|
it->second = 0;
|
|
|
|
++it->second;
|
2011-12-12 10:05:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
2014-04-28 01:48:24 +00:00
|
|
|
<< "HashMap. Size: " << map.size()
|
2011-12-12 10:05:35 +00:00
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
2012-06-01 10:45:29 +00:00
|
|
|
<< ", collisions: " << map.getCollisions()
|
2011-12-12 10:05:35 +00:00
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2011-12-19 02:00:40 +00:00
|
|
|
{
|
2011-12-12 10:05:35 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
|
2014-04-28 01:48:24 +00:00
|
|
|
std::unordered_map<Key, Value, DB::DefaultHash<Key> > map;
|
2011-12-12 10:05:35 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2012-06-01 10:45:29 +00:00
|
|
|
++map[data[i]];
|
|
|
|
|
2011-12-12 10:05:35 +00:00
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
2014-01-08 16:33:28 +00:00
|
|
|
<< "std::unordered_map. Size: " << map.size()
|
2011-12-12 10:05:35 +00:00
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
|
|
|
<< std::endl;
|
2011-12-19 02:00:40 +00:00
|
|
|
}
|
2011-12-12 10:05:35 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
Stopwatch watch;
|
|
|
|
|
2014-04-28 01:48:24 +00:00
|
|
|
google::dense_hash_map<Key, Value, DB::DefaultHash<Key> > map;
|
2012-06-01 10:45:29 +00:00
|
|
|
map.set_empty_key(-1ULL);
|
2011-12-12 10:05:35 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2012-06-01 10:45:29 +00:00
|
|
|
++map[data[i]];
|
|
|
|
|
2011-12-12 10:05:35 +00:00
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
2011-12-19 02:00:40 +00:00
|
|
|
<< "google::dense_hash_map. Size: " << map.size()
|
2011-12-12 10:05:35 +00:00
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2012-06-01 10:45:29 +00:00
|
|
|
{
|
2011-12-12 10:05:35 +00:00
|
|
|
Stopwatch watch;
|
|
|
|
|
2014-04-28 01:48:24 +00:00
|
|
|
google::sparse_hash_map<Key, Value, DB::DefaultHash<Key> > map;
|
2011-12-12 10:05:35 +00:00
|
|
|
for (size_t i = 0; i < n; ++i)
|
2012-06-01 10:45:29 +00:00
|
|
|
++map[data[i]];
|
2011-12-12 10:05:35 +00:00
|
|
|
|
|
|
|
watch.stop();
|
|
|
|
std::cerr << std::fixed << std::setprecision(2)
|
2011-12-19 02:00:40 +00:00
|
|
|
<< "google::sparse_hash_map. Size: " << map.size()
|
2011-12-12 10:05:35 +00:00
|
|
|
<< ", elapsed: " << watch.elapsedSeconds()
|
|
|
|
<< " (" << n / watch.elapsedSeconds() << " elem/sec.)"
|
|
|
|
<< std::endl;
|
2012-06-01 10:45:29 +00:00
|
|
|
}
|
|
|
|
|
2011-12-12 10:05:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|