From c60d59cb7a6e5ae87569de2ce1321f35df0bc787 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 7 Dec 2019 19:21:21 +0100 Subject: [PATCH] Port all benchs to new infrastructure --- bench/Makefile | 18 ++++++++-------- bench/bench-boost.cpp | 12 +++++------ bench/bench-concurrentqueue.cpp | 12 +++++------ bench/bench-densehashmap.cpp | 14 ++++++------ bench/bench-flathashmap.cpp | 17 +++++++-------- bench/bench-hopscotchmap.cpp | 15 +++++++------ bench/bench-liblfds.c | 1 - bench/bench-qt.cpp | 26 ++++++++++------------ bench/bench-sparsepp.cpp | 14 ++++++------ bench/bench-stl.cpp | 38 +++++++++++++-------------------- bench/common.c | 2 ++ bench/common.h | 5 +---- 12 files changed, 78 insertions(+), 96 deletions(-) diff --git a/bench/Makefile b/bench/Makefile index 222ff9f9..1735d373 100644 --- a/bench/Makefile +++ b/bench/Makefile @@ -80,7 +80,7 @@ bench-mlib-thread: @./bench-mlib-thread.exe 66 bench-stl: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-stl.cpp -o bench-stl.exe + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) bench-stl.cpp common.c -o bench-stl.exe @./bench-stl.exe 10 @./bench-stl.exe 20 @./bench-stl.exe 30 @@ -96,7 +96,7 @@ bench-stl: bench-qt: @if test -n "$${QT}" ; then $(MAKE) bench-qt0 ; else echo "Nothing to be done for QT." ; fi bench-qt0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -fPIC `PKG_CONFIG_PATH="$${QT}" pkg-config --libs --cflags Qt5Core` bench-qt.cpp -o bench-qt.exe + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -fPIC `PKG_CONFIG_PATH="$${QT}" pkg-config --libs --cflags Qt5Core` bench-qt.cpp common.c -o bench-qt.exe @./bench-qt.exe 10 @./bench-qt.exe 20 @./bench-qt.exe 30 @@ -145,7 +145,7 @@ bench-sparsepp: @if test -n "$${SPARSEPP}" ; then $(MAKE) bench-sparsepp0 ; else echo "Nothing to be done for SPARSEPP." ; fi bench-sparsepp0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${SPARSEPP}" -I "$${SPARSEPP}/.." bench-sparsepp.cpp -o bench-sparsepp.exe + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${SPARSEPP}" -I "$${SPARSEPP}/.." bench-sparsepp.cpp common.c -o bench-sparsepp.exe @./bench-sparsepp.exe 41 @./bench-sparsepp.exe 42 @./bench-sparsepp.exe 43 @@ -155,7 +155,7 @@ bench-densehashmap: @if test -n "$${DENSEHASHMAP}" ; then $(MAKE) bench-densehashmap0 ; else echo "Nothing to be done Google DENSEHASHMAP." ; fi bench-densehashmap0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${DENSEHASHMAP}" -I "$${DENSEHASHMAP}/.." bench-densehashmap.cpp -o bench-densehashmap.exe + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${DENSEHASHMAP}" -I "$${DENSEHASHMAP}/.." bench-densehashmap.cpp common.c -o bench-densehashmap.exe @./bench-densehashmap.exe 41 @./bench-densehashmap.exe 42 @./bench-densehashmap.exe 43 @@ -190,7 +190,7 @@ bench-flathashmap: @if test -n "$${FLATHASHMAP}" ; then $(MAKE) bench-flathashmap0 ; else echo "Nothing to be done for FLATHASHMAP." ; fi bench-flathashmap0: - $(CXX) -std=c++14 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${FLATHASHMAP}" bench-flathashmap.cpp -o bench-flathashmap.exe + $(CXX) -std=c++14 $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${FLATHASHMAP}" bench-flathashmap.cpp common.c -o bench-flathashmap.exe @./bench-flathashmap.exe 41 @./bench-flathashmap.exe 42 @./bench-flathashmap.exe 46 @@ -201,7 +201,7 @@ bench-hopscotchmap: @if test -n "$${HOPSCOTCHMAP}" ; then $(MAKE) bench-hopscotchmap0 ; else echo "Nothing to be done for HOPSCOTCHMAP." ; fi bench-hopscotchmap0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${HOPSCOTCHMAP}/include/tsl" bench-hopscotchmap.cpp -o bench-hopscotchmap.exe + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${HOPSCOTCHMAP}/include/tsl" bench-hopscotchmap.cpp common.c -o bench-hopscotchmap.exe @./bench-hopscotchmap.exe 41 @./bench-hopscotchmap.exe 42 @./bench-hopscotchmap.exe 43 @@ -251,7 +251,7 @@ bench-libsrt0: bench-liblfds: @if test -n "$${LIBLFDS}" ; then $(MAKE) bench-liblfds0 ; else echo "Nothing to be done for LIBLFDS." ; fi bench-liblfds0: - $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" -Wno-unknown-pragmas bench-liblfds.c common.c -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.a -lpthread + $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${LIBLFDS}/inc" -Wno-unknown-pragmas bench-liblfds.c common.c -DMULTI_THREAD_MEASURE -o bench-liblfds.exe $${LIBLFDS}/bin/liblfds711.a -lpthread @LD_LIBRARY_PATH="$${LIBLFDS}/bin:$${LD_LIBRARY_PATH}" ./bench-liblfds.exe 60 @@ -260,7 +260,7 @@ bench-liblfds0: bench-concurrentqueue: @if test -n "$${CONCURRENTQUEUE}" ; then $(MAKE) bench-concurrentqueue0 ; else echo "Nothing to be done for CONCURRENTQUEUE." ; fi bench-concurrentqueue0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp -o bench-concurrentqueue.exe -lpthread + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${CONCURRENTQUEUE}/" bench-concurrentqueue.cpp common.c -DMULTI_THREAD_MEASURE -o bench-concurrentqueue.exe -lpthread @./bench-concurrentqueue.exe 60 @@ -276,7 +276,7 @@ bench-xxhash0: bench-boost: @if test -n "$${BOOST}" ; then $(MAKE) bench-boost0 ; else echo "Nothing to be done for BOOST." ; fi bench-boost0: - $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp -o bench-boost.exe -lpthread + $(CXX) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) -I "$${BOOST}" bench-boost.cpp common.c -DMULTI_THREAD_MEASURE -o bench-boost.exe -lpthread @./bench-boost.exe 60 # NEDTRIES shall point to the header location. diff --git a/bench/bench-boost.cpp b/bench/bench-boost.cpp index 36e5133c..c83ff1d6 100644 --- a/bench/bench-boost.cpp +++ b/bench/bench-boost.cpp @@ -6,11 +6,8 @@ #include -#include "m-mutex.h" -#define MULTI_THREAD_MEASURE #include "common.h" - /********************************************************************************************/ boost::lockfree::queue> g_buff; boost::lockfree::queue> g_final; @@ -88,11 +85,12 @@ static void test_queue(size_t n) /********************************************************************************************/ +const config_func_t table[] = { + { 60, "Queue MPMC", 1000000, 0, test_queue, 0} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 60) - test_function("Queue MPMC", 1000000, test_queue); + test("BOOST-LOCKFREE", numberof(table), table, argc, argv); exit(0); } - diff --git a/bench/bench-concurrentqueue.cpp b/bench/bench-concurrentqueue.cpp index a57708d8..a073acd1 100644 --- a/bench/bench-concurrentqueue.cpp +++ b/bench/bench-concurrentqueue.cpp @@ -6,11 +6,8 @@ #include "concurrentqueue.h" -#include "m-mutex.h" -#define MULTI_THREAD_MEASURE #include "common.h" - /********************************************************************************************/ moodycamel::ConcurrentQueue g_buff; moodycamel::ConcurrentQueue g_final; @@ -88,11 +85,12 @@ static void test_queue(size_t n) /********************************************************************************************/ +const config_func_t table[] = { + { 60, "Queue MPMC", 1000000, 0, test_queue, 0} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 60) - test_function("Queue MPMC", 1000000, test_queue); + test("CONCURRENT-QUEUE", numberof(table), table, argc, argv); exit(0); } - diff --git a/bench/bench-densehashmap.cpp b/bench/bench-densehashmap.cpp index fe7125a2..4408669b 100644 --- a/bench/bench-densehashmap.cpp +++ b/bench/bench-densehashmap.cpp @@ -131,14 +131,14 @@ test_dict_str(size_t n) /********************************************************************************************/ +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} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 42) - test_function("Dict", 1000000, test_dict2); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 43) - test_function("DictStr", 1000000, test_dict_str); + test("DENSE-HASPMAP", numberof(table), table, argc, argv); exit(0); } diff --git a/bench/bench-flathashmap.cpp b/bench/bench-flathashmap.cpp index fdf8cb2a..f84ea761 100644 --- a/bench/bench-flathashmap.cpp +++ b/bench/bench-flathashmap.cpp @@ -125,16 +125,15 @@ test_dict_str(size_t n) /********************************************************************************************/ +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} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 42) - test_function("Dict", 1000000, test_dict2); - if (n == 46) - test_function("DictLinear", 1000000, test_dict2_linear); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 43) - test_function("DictStr", 1000000, test_dict_str); + test("DENSE-HASPMAP", numberof(table), table, argc, argv); exit(0); } diff --git a/bench/bench-hopscotchmap.cpp b/bench/bench-hopscotchmap.cpp index 4a0a169a..eb6b0dae 100644 --- a/bench/bench-hopscotchmap.cpp +++ b/bench/bench-hopscotchmap.cpp @@ -109,14 +109,15 @@ test_dict_str(size_t n) /********************************************************************************************/ +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} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 42) - test_function("Dict", 1000000, test_dict2); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 43) - test_function("DictStr", 1000000, test_dict_str); + test("HOPSCOTCHMAP", numberof(table), table, argc, argv); exit(0); + } diff --git a/bench/bench-liblfds.c b/bench/bench-liblfds.c index 411b74a3..832bfb21 100644 --- a/bench/bench-liblfds.c +++ b/bench/bench-liblfds.c @@ -6,7 +6,6 @@ #include "liblfds711.h" -#define MULTI_THREAD_MEASURE #include "common.h" /********************************************************************************************/ diff --git a/bench/bench-qt.cpp b/bench/bench-qt.cpp index cc545bff..cdeb3b9d 100644 --- a/bench/bench-qt.cpp +++ b/bench/bench-qt.cpp @@ -162,22 +162,18 @@ static void test_sort(size_t n) /********************************************************************************************/ +const config_func_t table[] = { + { 10, "List", 10000000, 0, test_list, 0}, + { 20, "Array", 100000000, 0, test_array, 0}, + { 30, "Rbtree", 1000000, 0, test_rbtree, 0}, + { 40, "dict(m)", 1000000, 0, test_dict1, 0}, + { 41, "dictBig", 1000000, 0, test_dict_big, 0}, + { 42,"dict(u)", 1000000, 0, test_dict2, 0}, + { 50, "Sort",10000000, 0, test_sort, 0} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 10) - test_function("List",10000000, test_list); - if (n == 20) - test_function("Array", 100000000, test_array); - if (n == 30) - test_function("Rbtree", 1000000, test_rbtree); - if (n == 40) - test_function("Dict(m)", 1000000, test_dict1); - if (n == 42) - test_function("Dict(u)", 1000000, test_dict2); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 50) - test_function("Sort", 10000000, test_sort); + test("QT", numberof(table), table, argc, argv); exit(0); } diff --git a/bench/bench-sparsepp.cpp b/bench/bench-sparsepp.cpp index 092cb746..fcec54fb 100644 --- a/bench/bench-sparsepp.cpp +++ b/bench/bench-sparsepp.cpp @@ -109,14 +109,14 @@ test_dict_str(size_t n) /********************************************************************************************/ +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} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 42) - test_function("Dict", 1000000, test_dict2); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 43) - test_function("DictStr", 1000000, test_dict_str); + test("SPARSEPP", numberof(table), table, argc, argv); exit(0); } diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index 996f1935..ee56b840 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -238,30 +238,22 @@ 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}, + { 30, "Rbtree", 1000000, 0, test_rbtree, 0}, + { 40, "dict(m)", 1000000, 0, test_dict1, 0}, + { 41, "dictBig", 1000000, 0, test_dict_big, 0}, + { 42,"dict(u)", 1000000, 0, test_dict2, 0}, + { 43,"DictStr(u)", 1000000, 0, test_dict_str, 0}, + { 44,"DictStr(m)", 1000000, 0, test_dict_str2, 0}, + { 46, "dictLinear(u)", 1000000, 0, test_dict2_linear, 0}, + { 50, "Sort",10000000, 0, test_sort, 0}, + { 51, "Stable Sort",10000000, 0, test_stable_sort, 0} +}; + int main(int argc, const char *argv[]) { - int n = (argc > 1) ? atoi(argv[1]) : 0; - if (n == 10) - test_function("List",10000000, test_list); - if (n == 20) - test_function("Array", 100000000, test_array); - if (n == 30) - test_function("Rbtree", 1000000, test_rbtree); - if (n == 40) - test_function("Dict(m)", 1000000, test_dict1); - if (n == 42) - test_function("Dict(u)", 1000000, test_dict2); - if (n == 46) - test_function("DictLinear(u)", 1000000, test_dict2_linear); - if (n == 41) - test_function("DictBig", 1000000, test_dict_big); - if (n == 43) - test_function("DictStr(u)", 1000000, test_dict_str); - if (n == 44) - test_function("DictStr(m)", 1000000, test_dict_str2); - if (n == 50) - test_function("Sort", 10000000, test_sort); - if (n == 51) - test_function("Stable Sort", 10000000, test_stable_sort); + test("STL", numberof(table), table, argc, argv); exit(0); } diff --git a/bench/common.c b/bench/common.c index 09ddbb92..9ffec95f 100644 --- a/bench/common.c +++ b/bench/common.c @@ -26,6 +26,8 @@ #include #include "common.h" +unsigned long g_result; + void compiler_barrier(void *p) { // Do nothing, but let the compiler thinks that we did. diff --git a/bench/common.h b/bench/common.h index 11962e64..898afbc3 100644 --- a/bench/common.h +++ b/bench/common.h @@ -87,10 +87,7 @@ cputime (void) #endif // The result of the bench -#ifdef __cplusplus -static -#endif -unsigned long g_result; +extern unsigned long g_result; // The rand value static