forked from rurban/smhasher
-
Notifications
You must be signed in to change notification settings - Fork 10
/
HashMapTest.cpp
59 lines (54 loc) · 1.52 KB
/
HashMapTest.cpp
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
50
51
52
53
54
55
56
57
58
59
#include "Platform.h"
#include "HashMapTest.h"
#include "SpeedTest.h"
#include "Random.h"
#include <string>
#include <unordered_map>
#include <functional>
#include <iostream>
#include <fstream>
using namespace std;
//-----------------------------------------------------------------------------
// This should be a realistic I-Cache test, when our hash is used inlined
// in a hash table. There the size matters more than the bulk speed.
std::vector<std::string> HashMapInit(bool verbose) {
std::vector<std::string> words;
std::string line;
std::string filename = "/usr/share/dict/words";
int lines = 0, sum = 0;
std::ifstream wordfile(filename.c_str());
if (!wordfile.is_open()) {
std::cout << "Unable to open words dict file " << filename << "\n";
return words;
}
while (getline(wordfile, line)) {
int len = line.length();
lines++;
sum += len;
words.push_back(line);
}
wordfile.close();
if (verbose) {
printf ("Read %d words from '%s'\n", lines, filename.c_str());
printf ("Avg len: %0.3f\n", (sum+0.0)/lines);
}
return words;
}
bool HashMapTest ( pfHash pfhash,
const int hashbits, std::vector<std::string> words,
const int trials, bool verbose )
{
double mean = 0.0;
try {
mean = HashMapSpeedTest( pfhash, hashbits, words, trials, verbose);
}
catch (...) {
printf(" aborted !!!!\n");
}
// if faster than ~sha1
if (mean > 5. && mean < 1500.)
printf(" ....... PASS\n");
else
printf(" ....... FAIL\n");
return true;
}