diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index 352d01a1..0305f713 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -8,6 +8,7 @@ #include "m-list.h" #include "m-rbtree.h" #include "m-bptree.h" +#include "m-deque.h" #include "m-dict.h" #include "m-algo.h" #include "m-mempool.h" @@ -43,6 +44,30 @@ static void test_array(size_t n) /********************************************************************************************/ +DEQUE_DEF(deque_uint, unsigned int) + +static void test_deque(size_t n) +{ + M_LET(a1, a2, DEQUE_OPLIST(deque_uint)) { + for(size_t i = 0; i < n; i++) { + deque_uint_push_back(a1, rand_get() ); + deque_uint_push_back(a2, rand_get() ); + } + unsigned int s = 0; + deque_uint_it_t it1, it2; + deque_uint_it(it1, a1); + deque_uint_it(it2, a2); + while (!deque_uint_end_p(it1)) { + s += *deque_uint_cref(it1 ) * *deque_uint_cref(it2 ); + deque_uint_next(it1); + deque_uint_next(it2); + } + g_result = s; + } +} + +/********************************************************************************************/ + // Two benched mode: with or without mempool #ifdef USE_MEMPOOL LIST_DEF(list_uint, unsigned int, (MEMPOOL( list_mpool), MEMPOOL_LINKAGE(static))) @@ -722,7 +747,6 @@ static void test_queue_single_bulk(size_t n) /********************************************************************************************/ -DEQUE_DEF(deque_uint, unsigned int) CONCURRENT_DEF(cdeque_uint, deque_uint_t, M_OPEXTEND(DEQUE_OPLIST(deque_uint, M_DEFAULT_OPLIST), PUSH(deque_uint_push_front))) DEQUE_DEF(deque_ull, unsigned long long) @@ -1031,6 +1055,7 @@ const config_func_t table[] = { { 10, "List", 10000000, 0, test_list, 0}, { 11, "DPList", 10000000, 0, test_dlist, 0}, { 20, "Array", 100000000, 0, test_array, 0}, + { 21, "Deque", 100000000, 0, test_deque, 0}, { 30, "Rbtree", 1000000, 0, test_rbtree, 0}, { 31, "B+tree", 1000000, 0, test_bptree, 0}, { 40, "dict", 1000000, 0, test_dict, 0}, diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index ee56b840..ab019d91 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -1,6 +1,7 @@ #define NDEBUG #include +#include #include #include #include @@ -53,6 +54,23 @@ static void test_array(size_t n) /********************************************************************************************/ +static void test_deque(size_t n) +{ + deque a1, a2; + for(size_t i = 0; i < n; i++) { + a1.push_back(rand_get() ); + a2.push_back(rand_get() ); + } + unsigned int s = 0; + for(auto it1 = a1.cbegin(), it2 = a2.cbegin(); + it1 != a1.cend() ;it1++, it2++) { + s += *it1 * *it2; + } + g_result = s; +} + +/********************************************************************************************/ + static void test_rbtree(size_t n) { set tree; @@ -241,6 +259,7 @@ static void test_stable_sort(size_t n) const config_func_t table[] = { { 10, "List", 10000000, 0, test_list, 0}, { 20, "Array", 100000000, 0, test_array, 0}, + { 21, "Deque", 100000000, 0, test_deque, 0}, { 30, "Rbtree", 1000000, 0, test_rbtree, 0}, { 40, "dict(m)", 1000000, 0, test_dict1, 0}, { 41, "dictBig", 1000000, 0, test_dict_big, 0},