From 9768b5b37a5124cef0ccc8568f2862aa35d8fb4e Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Tue, 3 Apr 2018 20:07:21 +0200 Subject: [PATCH] Add bench of B+TREE --- bench/Makefile | 2 ++ bench/bench-mlib.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/bench/Makefile b/bench/Makefile index a3366e1e..8302a68b 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -36,6 +36,7 @@ bench-mlib: @./bench-mlib.exe 10 @./bench-mlib.exe 20 @./bench-mlib.exe 30 + @./bench-mlib.exe 31 @./bench-mlib.exe 40 @./bench-mlib.exe 41 @./bench-mlib.exe 42 @@ -48,6 +49,7 @@ bench-mlib-mempool: @./bench-mlib-mempool.exe 10 @./bench-mlib-mempool.exe 20 @./bench-mlib-mempool.exe 30 + @./bench-mlib-mempool.exe 31 @./bench-mlib-mempool.exe 40 @./bench-mlib-mempool.exe 41 @./bench-mlib-mempool.exe 42 diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index 2a71bee4..78f6902b 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -7,6 +7,7 @@ #include "m-array.h" #include "m-list.h" #include "m-rbtree.h" +#include "m-bptree.h" #include "m-dict.h" #include "m-algo.h" #include "m-mempool.h" @@ -99,6 +100,29 @@ static void test_rbtree(size_t n) /********************************************************************************************/ +BPTREE_DEF(bptree_ulong, 21, unsigned long, M_DEFAULT_OPLIST) + +static void test_bptree(size_t n) +{ + bptree_ulong_t tree; + bptree_ulong_init(tree); + // M_LET(tree, RBTREE_OPLIST(rbtree_ulong)) { + for (size_t i = 0; i < n; i++) { + bptree_ulong_push(tree, rand_get()); + } + rand_init(); + unsigned int s = 0; + for (size_t i = 0; i < n; i++) { + unsigned long *p = bptree_ulong_get(tree, rand_get()); + if (p) + s += *p; + } + g_result = s; + bptree_ulong_clear(tree); +} + +/********************************************************************************************/ + #ifdef USE_MEMPOOL DICT_DEF2(dict_ulong, unsigned long, M_OPEXTEND(M_DEFAULT_OPLIST, MEMPOOL(dict_mpool), MEMPOOL_LINKAGE(static)), unsigned long, M_DEFAULT_OPLIST) #else @@ -486,6 +510,8 @@ int main(int argc, const char *argv[]) test_function("Array time", 100000000, test_array); if (n == 30) test_function("Rbtree time", 1000000, test_rbtree); + if (n == 31) + test_function("B+tree time", 1000000, test_bptree); if (n == 40) test_function("Dict time", 1000000, test_dict); if (n == 42)