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 { class SearchUrlsBenchmark : public UrlsBenchmark {
public: public:
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches) SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio)
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(0.2) {} : UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {}
protected: protected:
virtual bool SetUp(); virtual bool SetUp();
const uint32_t nsearches_; const uint32_t nsearches_;

View File

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

View File

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