Add bench of boost unordered flat hashmap
This commit is contained in:
1 parent
6a5c136c72
commit
91a602f774
2 files changed
+120
-3
No files matched your search
+5
-2
@@ -322,8 +322,11 @@ bench-xxhash0:
|
|||||||
bench-boost:
|
bench-boost:
|
||||||
@if test -n "$${BOOST}" ; then $(MAKE) bench-boost0 ; else echo "Nothing to be done for BOOST." ; fi
|
@if test -n "$${BOOST}" ; then $(MAKE) bench-boost0 ; else echo "Nothing to be done for BOOST." ; fi
|
||||||
bench-boost0:
|
bench-boost0:
|
||||||
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp common.c -DMULTI_THREAD_MEASURE -o bench-boost.exe -lpthread
|
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp common.c -DMULTI_THREAD_MEASURE -o bench-boost-thread.exe -lpthread
|
||||||
@./bench-boost.exe 60
|
$(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp common.c -o bench-boost.exe -lpthread
|
||||||
|
@./bench-boost.exe 42
|
||||||
|
@./bench-boost.exe 41
|
||||||
|
@./bench-boost-thread.exe 60
|
||||||
|
|
||||||
# NEDTRIES shall point to the header location.
|
# NEDTRIES shall point to the header location.
|
||||||
bench-nedtries:
|
bench-nedtries:
|
||||||
|
|||||||
+115
-1
@@ -3,11 +3,121 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include "m-thread.h"
|
||||||
|
|
||||||
|
#include <boost/unordered/unordered_flat_map.hpp>
|
||||||
#include <boost/lockfree/queue.hpp>
|
#include <boost/lockfree/queue.hpp>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_dict2(size_t n)
|
||||||
|
{
|
||||||
|
boost::unordered_flat_map<unsigned long, unsigned long> dict;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
dict[rand_get()] = rand_get();
|
||||||
|
}
|
||||||
|
rand_init();
|
||||||
|
unsigned int s = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
boost::unordered_flat_map<unsigned long, unsigned long>::iterator it = dict.find(rand_get());
|
||||||
|
if (it != dict.end())
|
||||||
|
s += it->second;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_dict2_linear(size_t n)
|
||||||
|
{
|
||||||
|
boost::unordered_flat_map<unsigned long, unsigned long> dict;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
dict[i] = rand_get();
|
||||||
|
}
|
||||||
|
rand_init();
|
||||||
|
unsigned int s = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
boost::unordered_flat_map<unsigned long, unsigned long>::iterator it = dict.find(i);
|
||||||
|
if (it != dict.end())
|
||||||
|
s += it->second;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
struct char_array_s {
|
||||||
|
char a[256];
|
||||||
|
char_array_s () { a[0] = 0 ; }
|
||||||
|
char_array_s ( const char_array_s & other) { strcpy(a, other.a); }
|
||||||
|
bool operator==(const char_array_s &other) const { return strcmp(a, other.a) == 0; }
|
||||||
|
};
|
||||||
|
|
||||||
|
inline std::size_t hash_value(const char_array_s &k) {
|
||||||
|
size_t hash = 0;
|
||||||
|
const char *s = k.a;
|
||||||
|
while (*s) hash = hash * 31421 + (*s++) + 6927;
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Hash32 {
|
||||||
|
//using is_avalanching = void;
|
||||||
|
inline std::size_t operator()(const char_array_s &k) const {
|
||||||
|
size_t hash = 0;
|
||||||
|
const char *s = k.a;
|
||||||
|
while (*s) hash = hash * 31421 + (*s++) + 6927;
|
||||||
|
return hash;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_dict_big(size_t n)
|
||||||
|
{
|
||||||
|
boost::unordered_flat_map<char_array_s, char_array_s> dict;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
char_array_s s1, s2;
|
||||||
|
sprintf(s1.a, "%u", rand_get());
|
||||||
|
sprintf(s2.a, "%u", rand_get());
|
||||||
|
dict[s1] = s2;
|
||||||
|
}
|
||||||
|
rand_init();
|
||||||
|
unsigned int s = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
char_array_s s1;
|
||||||
|
sprintf(s1.a, "%u", rand_get());
|
||||||
|
boost::unordered_flat_map<char_array_s, char_array_s>::iterator it = dict.find(s1);
|
||||||
|
if (it != dict.end())
|
||||||
|
s ++;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
static void
|
||||||
|
test_dict_str(size_t n)
|
||||||
|
{
|
||||||
|
boost::unordered_flat_map<string, string> dict;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
|
||||||
|
string s2 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
|
||||||
|
dict[s1] = s2;
|
||||||
|
}
|
||||||
|
rand_init();
|
||||||
|
unsigned int s = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
string s1 = static_cast<ostringstream*>( &(ostringstream() << rand_get()) )->str();
|
||||||
|
boost::unordered_flat_map<string, string>::iterator it = dict.find(s1);
|
||||||
|
if (it != dict.end())
|
||||||
|
s ++;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
boost::lockfree::queue<unsigned int, boost::lockfree::capacity<4*64>> g_buff;
|
boost::lockfree::queue<unsigned int, boost::lockfree::capacity<4*64>> g_buff;
|
||||||
boost::lockfree::queue<unsigned long long, boost::lockfree::capacity<4*64>> g_final;
|
boost::lockfree::queue<unsigned long long, boost::lockfree::capacity<4*64>> g_final;
|
||||||
@@ -86,11 +196,15 @@ static void test_queue(size_t n)
|
|||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
const config_func_t table[] = {
|
const config_func_t table[] = {
|
||||||
|
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
|
||||||
|
{ 42, "dict", 1000000, 0, test_dict2, 0},
|
||||||
|
{ 43, "DictStr", 1000000, 0, test_dict_str, 0},
|
||||||
|
{ 46, "DictLinear", 1000000, 0, test_dict2_linear, 0},
|
||||||
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
|
{ 60, "Queue MPMC", 1000000, 0, test_queue, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
test("BOOST-LOCKFREE", numberof(table), table, argc, argv);
|
test("BOOST", numberof(table), table, argc, argv);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user