2012-03-07 04:25:05 +02:00
|
|
|
#include <cmath>
|
2011-06-13 09:14:15 +03:00
|
|
|
#include <fstream>
|
2012-03-07 04:25:05 +02:00
|
|
|
#include <limits>
|
2011-06-13 09:14:15 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include "bm_common.h"
|
|
|
|
|
|
|
|
using std::cerr;
|
|
|
|
using std::endl;
|
|
|
|
using std::set;
|
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace cxxmph {
|
|
|
|
|
|
|
|
bool UrlsBenchmark::SetUp() {
|
|
|
|
vector<string> urls;
|
|
|
|
std::ifstream f(urls_file_.c_str());
|
|
|
|
if (!f.is_open()) {
|
|
|
|
cerr << "Failed to open urls file " << urls_file_ << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
string buffer;
|
|
|
|
while(std::getline(f, buffer)) urls.push_back(buffer);
|
|
|
|
set<string> unique(urls.begin(), urls.end());
|
|
|
|
if (unique.size() != urls.size()) {
|
|
|
|
cerr << "Input file has repeated keys." << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
urls.swap(urls_);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchUrlsBenchmark::SetUp() {
|
|
|
|
if (!UrlsBenchmark::SetUp()) return false;
|
2012-03-07 04:25:05 +02:00
|
|
|
int32_t miss_ratio_int32 = std::numeric_limits<int32_t>::max() * miss_ratio_;
|
|
|
|
forced_miss_urls_.resize(nsearches_);
|
2011-06-13 09:14:15 +03:00
|
|
|
random_.resize(nsearches_);
|
|
|
|
for (int i = 0; i < nsearches_; ++i) {
|
|
|
|
random_[i] = urls_[random() % urls_.size()];
|
2012-03-07 04:25:05 +02:00
|
|
|
if (random() < miss_ratio_int32) {
|
|
|
|
forced_miss_urls_[i] = random_[i].as_string() + ".force_miss";
|
|
|
|
random_[i] = forced_miss_urls_[i];
|
|
|
|
}
|
2011-06-13 09:14:15 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Uint64Benchmark::SetUp() {
|
|
|
|
set<uint64_t> unique;
|
|
|
|
for (int i = 0; i < count_; ++i) {
|
|
|
|
uint64_t v;
|
|
|
|
do { v = random(); } while (unique.find(v) != unique.end());
|
|
|
|
values_.push_back(v);
|
|
|
|
unique.insert(v);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SearchUint64Benchmark::SetUp() {
|
|
|
|
if (!Uint64Benchmark::SetUp()) return false;
|
|
|
|
random_.resize(nsearches_);
|
|
|
|
for (int i = 0; i < nsearches_; ++i) {
|
2011-06-14 09:30:41 +03:00
|
|
|
uint32_t pos = random() % values_.size();
|
|
|
|
random_[i] = values_[pos];
|
2011-06-13 09:14:15 +03:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace cxxmph
|