From 00b875ea53ee2a9a3779782987569a88e295cb8d Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 14 Oct 2019 20:57:29 +0200 Subject: [PATCH] Add linear hash map bench --- bench/Makefile | 3 +++ bench/bench-mlib.c | 20 ++++++++++++++++++++ bench/bench-stl.cpp | 20 ++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/bench/Makefile b/bench/Makefile index 1c777833..56e1ef18 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -47,6 +47,7 @@ bench-mlib: @./bench-mlib.exe 40 @./bench-mlib.exe 41 @./bench-mlib.exe 42 + @./bench-mlib.exe 46 @./bench-mlib.exe 43 @./bench-mlib.exe 50 @./bench-mlib.exe 51 @@ -61,6 +62,7 @@ bench-mlib-mempool: @./bench-mlib-mempool.exe 40 @./bench-mlib-mempool.exe 41 @./bench-mlib-mempool.exe 42 + @./bench-mlib-mempool.exe 46 @./bench-mlib-mempool.exe 43 @./bench-mlib-mempool.exe 50 @./bench-mlib-mempool.exe 51 @@ -83,6 +85,7 @@ bench-stl: @./bench-stl.exe 40 @./bench-stl.exe 41 @./bench-stl.exe 42 + @./bench-stl.exe 46 @./bench-stl.exe 43 @./bench-stl.exe 50 @./bench-stl.exe 51 diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index 8c1ffbc9..9c91dca0 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -220,6 +220,24 @@ test_dict_oa(size_t n) } } +static void +test_dict_oa_linear(size_t n) +{ + M_LET(dict, DICT_OPLIST(dict_oa_ulong)) { + for (size_t i = 0; i < n; i++) { + dict_oa_ulong_set_at(dict, i, rand_get() ); + } + rand_init(); + unsigned int s = 0; + for (size_t i = 0; i < n; i++) { + unsigned long *p = dict_oa_ulong_get(dict, i); + if (p) + s += *p; + } + g_result = s; + } +} + /********************************************************************************************/ typedef char char_array_t[256]; @@ -809,6 +827,8 @@ int main(int argc, const char *argv[]) test_function("Dict time", 1000000, test_dict); if (n == 42) test_function("DictOA time", 1000000, test_dict_oa); + if (n == 46) + test_function("DictOA+l time", 1000000, test_dict_oa_linear); if (n == 41) test_function("DictB time", 1000000, test_dict_big); if (n == 43) diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index 18e282a9..826d162b 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -110,6 +110,24 @@ test_dict2(size_t n) g_result = s; } +static void +test_dict2_linear(size_t n) +{ + unordered_map 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++) { + unordered_map::iterator it = dict.find(i); + if (it != dict.end()) + s += it->second; + } + g_result = s; +} + /********************************************************************************************/ struct char_array_s { @@ -233,6 +251,8 @@ int main(int argc, const char *argv[]) test_function("Dict(m)time", 1000000, test_dict1); if (n == 42) test_function("Dict(u)time", 1000000, test_dict2); + if (n == 46) + test_function("Dict(u+l)time", 1000000, test_dict2_linear); if (n == 41) test_function("DictB time", 1000000, test_dict_big); if (n == 43)