Added miss ratio to benchmark tools.

This commit is contained in:
Davi Reis 2012-03-07 01:00:17 -05:00
parent 7b6c163075
commit b8b0cde5c7
3 changed files with 19 additions and 41 deletions

View File

@ -31,8 +31,8 @@ class UrlsBenchmark : public Benchmark {
class SearchUrlsBenchmark : public UrlsBenchmark {
public:
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches)
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(0.2) {}
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio)
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {}
protected:
virtual bool SetUp();
const uint32_t nsearches_;

View File

@ -42,7 +42,7 @@ class BM_STLIndexCreate : public UrlsBenchmark {
class BM_MPHIndexSearch : public SearchUrlsBenchmark {
public:
BM_MPHIndexSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches) { }
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
virtual void Run() {
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto idx = index_.index(*it);
@ -62,7 +62,7 @@ class BM_MPHIndexSearch : public SearchUrlsBenchmark {
class BM_CmphIndexSearch : public SearchUrlsBenchmark {
public:
BM_CmphIndexSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches) { }
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
~BM_CmphIndexSearch() { if (index_) cmph_destroy(index_); }
virtual void Run() {
for (auto it = random_.begin(); it != random_.end(); ++it) {
@ -112,7 +112,7 @@ class BM_CmphIndexSearch : public SearchUrlsBenchmark {
class BM_STLIndexSearch : public SearchUrlsBenchmark {
public:
BM_STLIndexSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches) { }
: SearchUrlsBenchmark(urls_file, nsearches, 0) { }
virtual void Run() {
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto idx = index_.find(*it);

View File

@ -10,24 +10,11 @@
namespace cxxmph {
uint64_t myfind(const unordered_map<uint64_t, uint64_t>& mymap, const uint64_t& k) {
template<class Container, class T>
const T* myfind(const Container& mymap, const T& k) {
auto it = mymap.find(k);
if (it == mymap.end()) return -1;
return it->second;
}
uint64_t myfind(const mph_map<uint64_t, uint64_t>& mymap, const uint64_t& k) {
return mymap.find(k)->second;
}
const StringPiece& myfind(const unordered_map<StringPiece, StringPiece, Murmur2StringPiece>& mymap, const StringPiece& k) {
auto it = mymap.find(k);
if (it == mymap.end()) return ".force_miss";
return it->second;
}
StringPiece myfind(const mph_map<StringPiece, StringPiece>& mymap, const StringPiece& k) {
auto it = mymap.find(k);
return it->second;
if (it == mymap.end()) return NULL;
return &it->second;
}
template <class MapType>
@ -45,26 +32,15 @@
template <class MapType>
class BM_SearchUrls : public SearchUrlsBenchmark {
public:
BM_SearchUrls(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches) { }
BM_SearchUrls(const std::string& urls_file, int nsearches, float miss_ratio)
: SearchUrlsBenchmark(urls_file, nsearches, miss_ratio) { }
virtual void Run() {
fprintf(stderr, "Running benchmark\n");
for (auto it = random_.begin(); it != random_.end(); ++it) {
if (it->ends_with(".force_miss")) {
fprintf(stderr, "About to miss\n");
} else {
fprintf(stderr, "No miss\n");
}
fprintf(stderr, "it: *%s\n", it->as_string().c_str());
auto v = myfind(mymap_, *it);
fprintf(stderr, "v: %s, it: *%s\n", v.as_string().c_str(), it->as_string().c_str());
if (v != *it && !it->ends_with(".force_miss")) {
fprintf(stderr, "Looked for %s got %s\n", it->data(), v.data());
exit(-1);
assert(it->ends_with(".force_miss") ^ v != NULL);
assert(!v || *v == *it);
}
}
fprintf(stderr, "Done running benchmark\n");
}
protected:
virtual bool SetUp() {
if (!SearchUrlsBenchmark::SetUp()) return false;
@ -96,8 +72,8 @@ class BM_SearchUint64 : public SearchUint64Benchmark {
virtual void Run() {
for (auto it = random_.begin(); it != random_.end(); ++it) {
auto v = myfind(mymap_, *it);
if (v != *it) {
fprintf(stderr, "Looked for %lu got %lu\n", *it, v);
if (*v != *it) {
fprintf(stderr, "Looked for %lu got %lu\n", *it, *v);
exit(-1);
}
}
@ -115,8 +91,10 @@ int main(int argc, char** argv) {
Benchmark::Register(new BM_CreateUrls<mph_map<StringPiece, StringPiece>>("URLS100k"));
Benchmark::Register(new BM_CreateUrls<unordered_map<StringPiece, StringPiece>>("URLS100k"));
*/
// Benchmark::Register(new BM_SearchUrls<mph_map<StringPiece, StringPiece>>("URLS100k", 10*1000 * 1000));
Benchmark::Register(new BM_SearchUrls<unordered_map<StringPiece, StringPiece, Murmur2StringPiece>>("URLS100k", 10));
Benchmark::Register(new BM_SearchUrls<mph_map<StringPiece, StringPiece>>("URLS100k", 10*1000 * 1000, 0));
Benchmark::Register(new BM_SearchUrls<unordered_map<StringPiece, StringPiece, Murmur2StringPiece>>("URLS100k", 10*1000 * 1000, 0));
Benchmark::Register(new BM_SearchUrls<mph_map<StringPiece, StringPiece>>("URLS100k", 10*1000 * 1000, 0.9));
Benchmark::Register(new BM_SearchUrls<unordered_map<StringPiece, StringPiece, Murmur2StringPiece>>("URLS100k", 10*1000 * 1000, 0.9));
/*
Benchmark::Register(new BM_SearchUint64<unordered_map<uint64_t, uint64_t>>);
Benchmark::Register(new BM_SearchUint64<mph_map<uint64_t, uint64_t>>);