All compiles in the mac.
This commit is contained in:
parent
bbfcdeb5a6
commit
b10fe56a4e
|
@ -1,6 +1,6 @@
|
||||||
AM_CXXFLAGS='-std=c++0x'
|
AM_CXXFLAGS='-std=c++0x'
|
||||||
TESTS = $(check_PROGRAMS)
|
TESTS = $(check_PROGRAMS)
|
||||||
check_PROGRAMS = mph_map_test mph_index_test trigraph_test
|
check_PROGRAMS = mph_map_test mph_index_test # trigraph_test
|
||||||
noinst_PROGRAMS = bm_index bm_map
|
noinst_PROGRAMS = bm_index bm_map
|
||||||
bin_PROGRAMS = cxxmph
|
bin_PROGRAMS = cxxmph
|
||||||
lib_LTLIBRARIES = libcxxmph.la
|
lib_LTLIBRARIES = libcxxmph.la
|
||||||
|
@ -15,8 +15,8 @@ mph_map_test_SOURCES = mph_map_test.cc
|
||||||
mph_index_test_LDADD = libcxxmph.la
|
mph_index_test_LDADD = libcxxmph.la
|
||||||
mph_index_test_SOURCES = mph_index_test.cc
|
mph_index_test_SOURCES = mph_index_test.cc
|
||||||
|
|
||||||
trigraph_test_LDADD = libcxxmph.la
|
# trigraph_test_LDADD = libcxxmph.la
|
||||||
trigraph_test_SOURCES = trigraph_test.cc
|
# trigraph_test_SOURCES = trigraph_test.cc
|
||||||
|
|
||||||
bm_index_LDADD = libcxxmph.la
|
bm_index_LDADD = libcxxmph.la
|
||||||
bm_index_SOURCES = bm_common.cc bm_index.cc
|
bm_index_SOURCES = bm_common.cc bm_index.cc
|
||||||
|
|
|
@ -3,15 +3,22 @@
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <memory>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using std::cerr;
|
using std::cerr;
|
||||||
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
using std::setfill;
|
||||||
|
using std::setw;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
using std::ostringstream;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -42,6 +49,14 @@ int timeval_subtract (
|
||||||
return x->tv_sec < y->tv_sec;
|
return x->tv_sec < y->tv_sec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// C++ iostream is terrible for formatting.
|
||||||
|
string timeval_to_string(timeval tv) {
|
||||||
|
ostringstream out;
|
||||||
|
out << setfill(' ') << setw(3) << tv.tv_sec << '.';
|
||||||
|
out << setfill('0') << setw(6) << tv.tv_usec;
|
||||||
|
return out.str();
|
||||||
|
}
|
||||||
|
|
||||||
struct rusage getrusage_or_die() {
|
struct rusage getrusage_or_die() {
|
||||||
struct rusage rs;
|
struct rusage rs;
|
||||||
int ret = getrusage(RUSAGE_SELF, &rs);
|
int ret = getrusage(RUSAGE_SELF, &rs);
|
||||||
|
@ -92,11 +107,14 @@ namespace cxxmph {
|
||||||
|
|
||||||
/* static */ void Benchmark::RunAll() {
|
/* static */ void Benchmark::RunAll() {
|
||||||
for (int i = 0; i < g_benchmarks.size(); ++i) {
|
for (int i = 0; i < g_benchmarks.size(); ++i) {
|
||||||
Benchmark* bm = g_benchmarks[i];
|
std::auto_ptr<Benchmark> bm(g_benchmarks[i]);
|
||||||
bm->SetUp();
|
if (!bm->SetUp()) {
|
||||||
|
cerr << "Set up phase for benchmark "
|
||||||
|
<< bm->name() << " failed." << endl;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
bm->MeasureRun();
|
bm->MeasureRun();
|
||||||
bm->TearDown();
|
bm->TearDown();
|
||||||
delete bm;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,11 +132,11 @@ void Benchmark::MeasureRun() {
|
||||||
struct timeval wtime;
|
struct timeval wtime;
|
||||||
timeval_subtract(&wtime, &walltime_end, &walltime_begin);
|
timeval_subtract(&wtime, &walltime_end, &walltime_begin);
|
||||||
|
|
||||||
printf("Benchmark: %s\n", name().c_str());
|
cout << "Benchmark: " << name_ << endl;
|
||||||
printf("CPU User time : %ld.%06ld\n", utime.tv_sec, utime.tv_usec);
|
cout << "CPU User time : " << timeval_to_string(utime) << endl;
|
||||||
printf("CPU System time: %ld.%06ld\n", stime.tv_sec, stime.tv_usec);
|
cout << "CPU System time: " << timeval_to_string(stime) << endl;
|
||||||
printf("Wall clock time: %ld.%06ld\n", wtime.tv_sec, wtime.tv_usec);
|
cout << "Wall clock time: " << timeval_to_string(wtime) << endl;
|
||||||
printf("\n");
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace cxxmph
|
} // namespace cxxmph
|
||||||
|
|
|
@ -29,11 +29,12 @@ class BM_MapSearch : public SearchUrlsBenchmark {
|
||||||
: SearchUrlsBenchmark(urls_file, nsearches) { }
|
: SearchUrlsBenchmark(urls_file, nsearches) { }
|
||||||
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 value = mymap_[it->ToString()];
|
mymap_.find(*it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected:
|
protected:
|
||||||
virtual bool SetUp() {
|
virtual bool SetUp() {
|
||||||
|
if (!SearchUrlsBenchmark::SetUp()) return false;
|
||||||
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
for (auto it = urls_.begin(); it != urls_.end(); ++it) {
|
||||||
mymap_[*it] = *it;
|
mymap_[*it] = *it;
|
||||||
}
|
}
|
||||||
|
@ -48,9 +49,9 @@ class BM_MapSearch : public SearchUrlsBenchmark {
|
||||||
using namespace cxxmph;
|
using namespace cxxmph;
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
Benchmark::Register(new BM_MapCreate<mph_map<string, string>>("URLS100k"));
|
Benchmark::Register(new BM_MapCreate<mph_map<StringPiece, StringPiece>>("URLS100k"));
|
||||||
Benchmark::Register(new BM_MapCreate<unordered_map<string, string>>("URLS100k"));
|
Benchmark::Register(new BM_MapCreate<unordered_map<StringPiece, StringPiece>>("URLS100k"));
|
||||||
Benchmark::Register(new BM_MapSearch<mph_map<string, string>>("URLS100k", 1000 * 1000));
|
Benchmark::Register(new BM_MapSearch<mph_map<StringPiece, StringPiece>>("URLS100k", 1000* 1000));
|
||||||
Benchmark::Register(new BM_MapSearch<unordered_map<string, string>>("URLS100k", 1000 * 1000));
|
Benchmark::Register(new BM_MapSearch<unordered_map<StringPiece, StringPiece>>("URLS100k", 1000* 1000));
|
||||||
Benchmark::RunAll();
|
Benchmark::RunAll();
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,10 @@ class MPHIndex {
|
||||||
// Template method needs to go in the header file.
|
// Template method needs to go in the header file.
|
||||||
template <class SeededHashFcn, class ForwardIterator>
|
template <class SeededHashFcn, class ForwardIterator>
|
||||||
bool MPHIndex::Reset(ForwardIterator begin, ForwardIterator end) {
|
bool MPHIndex::Reset(ForwardIterator begin, ForwardIterator end) {
|
||||||
|
if (end == begin) {
|
||||||
|
clear();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
m_ = end - begin;
|
m_ = end - begin;
|
||||||
r_ = static_cast<uint32_t>(ceil((c_*m_)/3));
|
r_ = static_cast<uint32_t>(ceil((c_*m_)/3));
|
||||||
if ((r_ % 2) == 0) r_ += 1;
|
if ((r_ % 2) == 0) r_ += 1;
|
||||||
|
|
|
@ -60,6 +60,8 @@ template <> struct seeded_hash<std::tr1::hash<const char*> >
|
||||||
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
template <> struct seeded_hash<std::tr1::hash<std::string> >
|
template <> struct seeded_hash<std::tr1::hash<std::string> >
|
||||||
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
|
template <> struct seeded_hash<std::tr1::hash<cxxmph::StringPiece> >
|
||||||
|
{ typedef seeded_hash_function<Murmur2StringPiece> hash_function; };
|
||||||
|
|
||||||
template <> struct seeded_hash<std::tr1::hash<char> >
|
template <> struct seeded_hash<std::tr1::hash<char> >
|
||||||
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
{ typedef seeded_hash_function<Murmur2> hash_function; };
|
||||||
|
|
|
@ -145,32 +145,34 @@ class StringPiece {
|
||||||
StringPiece substr(size_type pos, size_type n = npos) const;
|
StringPiece substr(size_type pos, size_type n = npos) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace cxxmph
|
inline bool operator==(const StringPiece& x, const StringPiece& y) {
|
||||||
|
return x.length() == y.length() && memcmp(x.data(), y.data(), x.length()) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool operator==(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y);
|
inline bool operator!=(const StringPiece& x, const StringPiece& y) {
|
||||||
|
|
||||||
inline bool operator!=(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y) {
|
|
||||||
return !(x == y);
|
return !(x == y);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator<(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y) {
|
inline bool operator<(const StringPiece& x, const StringPiece& y) {
|
||||||
const int r = memcmp(x.data(), y.data(),
|
const int r = memcmp(x.data(), y.data(),
|
||||||
std::min(x.size(), y.size()));
|
std::min(x.size(), y.size()));
|
||||||
return ((r < 0) || ((r == 0) && (x.size() < y.size())));
|
return ((r < 0) || ((r == 0) && (x.size() < y.size())));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator>(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y) {
|
inline bool operator>(const StringPiece& x, const StringPiece& y) {
|
||||||
return y < x;
|
return y < x;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator<=(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y) {
|
inline bool operator<=(const StringPiece& x, const StringPiece& y) {
|
||||||
return !(x > y);
|
return !(x > y);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator>=(const cxxmph::StringPiece& x, const cxxmph::StringPiece& y) {
|
inline bool operator>=(const StringPiece& x, StringPiece& y) {
|
||||||
return !(x < y);
|
return !(x < y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace cxxmph
|
||||||
|
|
||||||
// allow StringPiece to be logged
|
// allow StringPiece to be logged
|
||||||
extern std::ostream& operator<<(std::ostream& o, const cxxmph::StringPiece& piece);
|
extern std::ostream& operator<<(std::ostream& o, const cxxmph::StringPiece& piece);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <ext/hash_set>
|
|
||||||
using __gnu_cxx::hash_set;
|
|
||||||
static const char cxx_name = "__gnu_cxx::hash_set";
|
|
||||||
|
|
||||||
#include "bitbool.h"
|
#include "bitbool.h"
|
||||||
#include "cmph.h"
|
#include "cmph.h"
|
||||||
#include "cmph_benchmark.h"
|
#include "cmph_benchmark.h"
|
||||||
|
@ -71,12 +67,12 @@ void bm_create(CMPH_ALGO algo, int iters) {
|
||||||
|
|
||||||
void bm_search(CMPH_ALGO algo, int iters) {
|
void bm_search(CMPH_ALGO algo, int iters) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char mphf_name[128];
|
char *mphf_name;
|
||||||
cmph_t* mphf = NULL;
|
cmph_t* mphf = NULL;
|
||||||
|
|
||||||
|
mphf_name = create_lsmap_key(algo, iters);
|
||||||
snprintf(mphf_name, 128, "%s:%u", cxx_name, iters);
|
|
||||||
mphf = (cmph_t*)lsmap_search(g_created_mphf, mphf_name);
|
mphf = (cmph_t*)lsmap_search(g_created_mphf, mphf_name);
|
||||||
|
free(mphf_name);
|
||||||
|
|
||||||
cmph_uint32* count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
cmph_uint32* count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
||||||
cmph_uint32* hash_count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
cmph_uint32* hash_count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
||||||
|
@ -106,49 +102,6 @@ DECLARE_ALGO(CMPH_BRZ);
|
||||||
DECLARE_ALGO(CMPH_FCH);
|
DECLARE_ALGO(CMPH_FCH);
|
||||||
DECLARE_ALGO(CMPH_BDZ);
|
DECLARE_ALGO(CMPH_BDZ);
|
||||||
|
|
||||||
void bm_create_ext_hash_set(int iters) {
|
|
||||||
cmph_uint32 i = 0;
|
|
||||||
|
|
||||||
if (iters > g_numbers_len) {
|
|
||||||
fprintf(stderr, "No input with proper size.");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
hash_set<cmph_uint32>* ext_hash_set = new hash_set<cmph_uint32>;
|
|
||||||
for (i = 0; i < iters; ++i) {
|
|
||||||
ext_hash_set->insert(g_numbers[i]);
|
|
||||||
}
|
|
||||||
lsmap_append(g_created_mphf, cxx_name, ext_hash_set);
|
|
||||||
}
|
|
||||||
|
|
||||||
void bm_search_ext_hash_set(int iters) {
|
|
||||||
cmph_uint32 i = 0;
|
|
||||||
|
|
||||||
if (iters > g_numbers_len) {
|
|
||||||
fprintf(stderr, "No input with proper size.");
|
|
||||||
exit(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(mphf_name, 128, "%s:%u", hash_count, iters);
|
|
||||||
mphf = (__gnu_cxx::hash_set*)lsmap_search(g_created_mphf, mphf_name);
|
|
||||||
|
|
||||||
cmph_uint32* count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
|
||||||
cmph_uint32* hash_count = (cmph_uint32*)malloc(sizeof(cmph_uint32)*iters);
|
|
||||||
|
|
||||||
for (i = 0; i < iters * 100; ++i) {
|
|
||||||
cmph_uint32 pos = random() % iters;
|
|
||||||
const char* buf = (const char*)(g_numbers + pos);
|
|
||||||
cmph_uint32 h = cmph_search(mphf, buf, sizeof(cmph_uint32));
|
|
||||||
++count[pos];
|
|
||||||
++hash_count[h];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify correctness later.
|
|
||||||
lsmap_append(g_expected_probes, create_lsmap_key(algo, iters), count);
|
|
||||||
lsmap_append(g_mphf_probes, create_lsmap_key(algo, iters), hash_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
g_numbers_len = 1000 * 1000;
|
g_numbers_len = 1000 * 1000;
|
||||||
g_numbers = random_numbers_vector_new(g_numbers_len);
|
g_numbers = random_numbers_vector_new(g_numbers_len);
|
||||||
|
@ -162,8 +115,8 @@ int main(int argc, char** argv) {
|
||||||
BM_REGISTER(bm_search_CMPH_CHM, 1000 * 1000);
|
BM_REGISTER(bm_search_CMPH_CHM, 1000 * 1000);
|
||||||
// BM_REGISTER(bm_create_CMPH_BRZ, 1000 * 1000);
|
// BM_REGISTER(bm_create_CMPH_BRZ, 1000 * 1000);
|
||||||
// BM_REGISTER(bm_search_CMPH_BRZ, 1000 * 1000);
|
// BM_REGISTER(bm_search_CMPH_BRZ, 1000 * 1000);
|
||||||
BM_REGISTER(bm_create_CMPH_FCH, 1000 * 1000);
|
// BM_REGISTER(bm_create_CMPH_FCH, 1000 * 1000);
|
||||||
BM_REGISTER(bm_search_CMPH_FCH, 1000 * 1000);
|
// BM_REGISTER(bm_search_CMPH_FCH, 1000 * 1000);
|
||||||
BM_REGISTER(bm_create_CMPH_BDZ, 1000 * 1000);
|
BM_REGISTER(bm_create_CMPH_BDZ, 1000 * 1000);
|
||||||
BM_REGISTER(bm_search_CMPH_BDZ, 1000 * 1000);
|
BM_REGISTER(bm_search_CMPH_BDZ, 1000 * 1000);
|
||||||
run_benchmarks(argc, argv);
|
run_benchmarks(argc, argv);
|
||||||
|
|
|
@ -111,8 +111,10 @@ void bm_end(const char* name) {
|
||||||
timeval_subtract(&stime, &benchmark->end.ru_stime, &benchmark->begin.ru_stime);
|
timeval_subtract(&stime, &benchmark->end.ru_stime, &benchmark->begin.ru_stime);
|
||||||
|
|
||||||
printf("Benchmark: %s\n", benchmark->name);
|
printf("Benchmark: %s\n", benchmark->name);
|
||||||
printf("User time used : %ld.%06ld\n", utime.tv_sec, utime.tv_usec);
|
printf("User time used : %ld.%06ld\n",
|
||||||
printf("System time used: %ld.%06ld\n", stime.tv_sec, stime.tv_usec);
|
utime.tv_sec, (long int)utime.tv_usec);
|
||||||
|
printf("System time used: %ld.%06ld\n",
|
||||||
|
stime.tv_sec, (long int)stime.tv_usec);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue