2011-12-05 20:03:10 +02:00
|
|
|
#ifndef __CXXMPH_BM_COMMON_H__
|
|
|
|
#define __CXXMPH_BM_COMMON_H__
|
|
|
|
|
2011-06-13 09:14:15 +03:00
|
|
|
#include "stringpiece.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2011-11-10 20:44:37 +02:00
|
|
|
#include <unordered_map> // std::hash
|
2011-06-13 09:14:15 +03:00
|
|
|
#include "MurmurHash2.h"
|
|
|
|
|
|
|
|
#include "benchmark.h"
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <> struct hash<cxxmph::StringPiece> {
|
|
|
|
uint32_t operator()(const cxxmph::StringPiece& k) const {
|
|
|
|
return cxxmph::MurmurHash2(k.data(), k.length(), 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace std
|
|
|
|
|
|
|
|
namespace cxxmph {
|
|
|
|
|
|
|
|
class UrlsBenchmark : public Benchmark {
|
|
|
|
public:
|
|
|
|
UrlsBenchmark(const std::string& urls_file) : urls_file_(urls_file) { }
|
|
|
|
protected:
|
|
|
|
virtual bool SetUp();
|
|
|
|
const std::string urls_file_;
|
|
|
|
std::vector<std::string> urls_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SearchUrlsBenchmark : public UrlsBenchmark {
|
|
|
|
public:
|
2012-03-07 08:00:17 +02:00
|
|
|
SearchUrlsBenchmark(const std::string& urls_file, uint32_t nsearches, float miss_ratio)
|
|
|
|
: UrlsBenchmark(urls_file), nsearches_(nsearches), miss_ratio_(miss_ratio) {}
|
2011-06-13 09:14:15 +03:00
|
|
|
protected:
|
|
|
|
virtual bool SetUp();
|
|
|
|
const uint32_t nsearches_;
|
2012-03-07 04:25:05 +02:00
|
|
|
float miss_ratio_;
|
|
|
|
std::vector<std::string> forced_miss_urls_;
|
2011-06-13 09:14:15 +03:00
|
|
|
std::vector<StringPiece> random_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class Uint64Benchmark : public Benchmark {
|
|
|
|
public:
|
|
|
|
Uint64Benchmark(uint32_t count) : count_(count) { }
|
|
|
|
virtual void Run() {}
|
|
|
|
protected:
|
|
|
|
virtual bool SetUp();
|
|
|
|
const uint32_t count_;
|
|
|
|
std::vector<uint64_t> values_;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SearchUint64Benchmark : public Uint64Benchmark {
|
|
|
|
public:
|
|
|
|
SearchUint64Benchmark(uint32_t count, uint32_t nsearches)
|
|
|
|
: Uint64Benchmark(count), nsearches_(nsearches) { }
|
|
|
|
virtual void Run() {};
|
|
|
|
protected:
|
|
|
|
virtual bool SetUp();
|
|
|
|
const uint32_t nsearches_;
|
2011-06-14 08:24:40 +03:00
|
|
|
std::vector<uint64_t> random_;
|
2011-06-13 09:14:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace cxxmph
|
2011-12-05 20:03:10 +02:00
|
|
|
|
|
|
|
#endif // __CXXMPH_BM_COMMON_H__
|