blob: 3e12290cf56ebc8d90ad9dee5c68d50c970b58a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
#include "util/probing_hash_table.hh"
#include "util/scoped.hh"
#include "util/usage.hh"
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/uniform_int_distribution.hpp>
#include <iostream>
namespace util {
namespace {
struct Entry {
typedef uint64_t Key;
Key key;
Key GetKey() const { return key; }
};
typedef util::ProbingHashTable<Entry, util::IdentityHash> Table;
void Test(uint64_t entries, uint64_t lookups, float multiplier = 1.5) {
std::size_t size = Table::Size(entries, multiplier);
scoped_malloc backing(util::CallocOrThrow(size));
Table table(backing.get(), size);
boost::random::mt19937 gen;
boost::random::uniform_int_distribution<> dist(std::numeric_limits<uint64_t>::min(), std::numeric_limits<uint64_t>::max());
double start = UserTime();
for (uint64_t i = 0; i < entries; ++i) {
Entry entry;
entry.key = dist(gen);
table.Insert(entry);
}
double inserted = UserTime();
bool meaningless = true;
for (uint64_t i = 0; i < lookups; ++i) {
Table::ConstIterator it;
meaningless ^= table.Find(dist(gen), it);
}
std::cout << meaningless << ' ' << entries << ' ' << multiplier << ' ' << (inserted - start) << ' ' << (UserTime() - inserted) / static_cast<double>(lookups) << std::endl;
}
} // namespace
} // namespace util
int main() {
for (uint64_t i = 1; i <= 10000000ULL; i *= 10) {
util::Test(i, 10000000);
}
}
|