1
Fork 0
turbonss/cxxmph/bm_map.cc

58 lines
1.5 KiB
C++
Raw Normal View History

#include <string>
2011-05-24 03:18:24 +03:00
#include <tr1/unordered_map>
#include "bm_common.h"
#include "mph_map.h"
using cxxmph::mph_map;
using std::string;
2011-05-24 03:18:24 +03:00
using std::tr1::unordered_map;
namespace cxxmph {
template <class MapType>
class BM_MapCreate : public UrlsBenchmark {
public:
2011-05-24 03:18:24 +03:00
BM_MapCreate(const string& urls_file) : UrlsBenchmark(urls_file) { }
virtual void Run() {
MapType mymap;
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
mymap[*it] = *it;
}
}
};
template <class MapType>
class BM_MapSearch : public SearchUrlsBenchmark {
public:
2011-05-24 03:18:24 +03:00
BM_MapSearch(const std::string& urls_file, int nsearches)
: SearchUrlsBenchmark(urls_file, nsearches) { }
virtual void Run() {
for (auto it = random_.begin(); it != random_.end(); ++it) {
2011-06-13 08:16:19 +03:00
mymap_.find(*it);
}
}
protected:
2011-05-24 03:18:24 +03:00
virtual bool SetUp() {
2011-06-13 08:16:19 +03:00
if (!SearchUrlsBenchmark::SetUp()) return false;
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
mymap_[*it] = *it;
}
2011-05-24 03:18:24 +03:00
mymap_.rehash(mymap_.bucket_count());
return true;
}
MapType mymap_;
};
} // namespace cxxmph
using namespace cxxmph;
int main(int argc, char** argv) {
2011-06-13 08:16:19 +03:00
Benchmark::Register(new BM_MapCreate<mph_map<StringPiece, StringPiece>>("URLS100k"));
Benchmark::Register(new BM_MapCreate<unordered_map<StringPiece, StringPiece>>("URLS100k"));
Benchmark::Register(new BM_MapSearch<mph_map<StringPiece, StringPiece>>("URLS100k", 1000* 1000));
Benchmark::Register(new BM_MapSearch<unordered_map<StringPiece, StringPiece>>("URLS100k", 1000* 1000));
Benchmark::RunAll();
}