Add bench for deque
This commit is contained in:
1 parent
ee64e068f9
commit
5ce6ccde3d
2 files changed
+45
-1
No files matched your search
+26
-1
@@ -8,6 +8,7 @@
|
|||||||
#include "m-list.h"
|
#include "m-list.h"
|
||||||
#include "m-rbtree.h"
|
#include "m-rbtree.h"
|
||||||
#include "m-bptree.h"
|
#include "m-bptree.h"
|
||||||
|
#include "m-deque.h"
|
||||||
#include "m-dict.h"
|
#include "m-dict.h"
|
||||||
#include "m-algo.h"
|
#include "m-algo.h"
|
||||||
#include "m-mempool.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
|
// Two benched mode: with or without mempool
|
||||||
#ifdef USE_MEMPOOL
|
#ifdef USE_MEMPOOL
|
||||||
LIST_DEF(list_uint, unsigned int, (MEMPOOL( list_mpool), MEMPOOL_LINKAGE(static)))
|
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)))
|
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)
|
DEQUE_DEF(deque_ull, unsigned long long)
|
||||||
@@ -1031,6 +1055,7 @@ const config_func_t table[] = {
|
|||||||
{ 10, "List", 10000000, 0, test_list, 0},
|
{ 10, "List", 10000000, 0, test_list, 0},
|
||||||
{ 11, "DPList", 10000000, 0, test_dlist, 0},
|
{ 11, "DPList", 10000000, 0, test_dlist, 0},
|
||||||
{ 20, "Array", 100000000, 0, test_array, 0},
|
{ 20, "Array", 100000000, 0, test_array, 0},
|
||||||
|
{ 21, "Deque", 100000000, 0, test_deque, 0},
|
||||||
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
|
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
|
||||||
{ 31, "B+tree", 1000000, 0, test_bptree, 0},
|
{ 31, "B+tree", 1000000, 0, test_bptree, 0},
|
||||||
{ 40, "dict", 1000000, 0, test_dict, 0},
|
{ 40, "dict", 1000000, 0, test_dict, 0},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#define NDEBUG
|
#define NDEBUG
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <deque>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <map>
|
#include <map>
|
||||||
@@ -53,6 +54,23 @@ static void test_array(size_t n)
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
static void test_deque(size_t n)
|
||||||
|
{
|
||||||
|
deque<unsigned int> 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)
|
static void test_rbtree(size_t n)
|
||||||
{
|
{
|
||||||
set<unsigned long> tree;
|
set<unsigned long> tree;
|
||||||
@@ -241,6 +259,7 @@ static void test_stable_sort(size_t n)
|
|||||||
const config_func_t table[] = {
|
const config_func_t table[] = {
|
||||||
{ 10, "List", 10000000, 0, test_list, 0},
|
{ 10, "List", 10000000, 0, test_list, 0},
|
||||||
{ 20, "Array", 100000000, 0, test_array, 0},
|
{ 20, "Array", 100000000, 0, test_array, 0},
|
||||||
|
{ 21, "Deque", 100000000, 0, test_deque, 0},
|
||||||
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
|
{ 30, "Rbtree", 1000000, 0, test_rbtree, 0},
|
||||||
{ 40, "dict(m)", 1000000, 0, test_dict1, 0},
|
{ 40, "dict(m)", 1000000, 0, test_dict1, 0},
|
||||||
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
|
{ 41, "dictBig", 1000000, 0, test_dict_big, 0},
|
||||||
|
|||||||
Reference in new issue
Block a user