From c5299589bb0f3eca874e7413a2f67e961f7b9064 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 26 Mar 2017 11:27:27 +0200 Subject: [PATCH] Fix representative issue in bench which result in too much computation being removed by the compiler. --- bench/bench-glib.c | 7 +++++++ bench/bench-klib.c | 7 +++++++ bench/bench-mlib.c | 7 +++++++ bench/bench-qt.cpp | 10 +++++++++- bench/bench-stl.cpp | 10 +++++++++- 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/bench/bench-glib.c b/bench/bench-glib.c index c1e646c8..1fdd44bd 100644 --- a/bench/bench-glib.c +++ b/bench/bench-glib.c @@ -10,6 +10,8 @@ #include +unsigned long g_result; + static unsigned long long cputime (void) { @@ -58,6 +60,7 @@ static void test_array(size_t n) for(unsigned long i = 0; i < n; i++) { s += g_array_index(a1, unsigned int, i ) * g_array_index(a2, unsigned int, i ); } + g_result = s; g_array_free(a1, FALSE); g_array_free(a2, FALSE); } @@ -78,6 +81,7 @@ static void test_list (size_t n) s += GPOINTER_TO_INT(it1->data) * GPOINTER_TO_INT(it2->data); n--; } + g_result = s; g_slist_free(a1); g_slist_free(a2); } @@ -109,6 +113,7 @@ static void test_rbtree(size_t n) if (p) s += *p; } + g_result = s; g_tree_destroy(tree); } @@ -145,6 +150,7 @@ test_dict(unsigned long n) if (p) s += *p; } + g_result = s; g_hash_table_destroy(dict); } @@ -188,6 +194,7 @@ test_dict_big(unsigned long n) if (p) s ++; } + g_result = s; g_hash_table_destroy(dict); } diff --git a/bench/bench-klib.c b/bench/bench-klib.c index 9e090b35..b90d5b31 100644 --- a/bench/bench-klib.c +++ b/bench/bench-klib.c @@ -12,6 +12,8 @@ #include "kbtree.h" #include "khash.h" +unsigned long g_result; + static unsigned long long cputime (void) { @@ -60,6 +62,7 @@ static void test_array(size_t n) for(unsigned long i = 0; i < n; i++) { s += kv_A(a1, i ) * kv_A(a2, i ); } + g_result = s; kv_destroy(a1); kv_destroy(a2); @@ -88,6 +91,7 @@ static void test_list (size_t n) it1 = kl_next(it1), it2 = kl_next(it2)) { s += kl_val(it1) * kl_val(it2); } + g_result = s; kl_destroy(32, a1); kl_destroy(32, a2); @@ -116,6 +120,7 @@ static void test_rbtree(size_t n) if (kb_getp(kTree, tree, &j) != 0) s+= j; } + g_result = s; kb_destroy(kTree, tree); } @@ -143,6 +148,7 @@ test_dict(unsigned long n) if (kh_exist(dict, k)) s += kh_value(dict, k); } + g_result = s; kh_destroy(iun, dict); } @@ -186,6 +192,7 @@ test_dict_big(unsigned long n) if (kh_exist(dict, k)) s ++; } + g_result = s; kh_destroy(iub, dict); } diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index d7f0d57c..04559d8f 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -12,6 +12,8 @@ #include "m-rbtree.h" #include "m-dict.h" +unsigned long g_result; + static unsigned long long cputime (void) { @@ -58,6 +60,7 @@ static void test_array(size_t n) for(unsigned long i = 0; i < n; i++) { s += *array_uint_cget(a1, i ) * *array_uint_cget(a2, i ); } + g_result = s; } } @@ -78,6 +81,7 @@ static void test_list (size_t n) for(list_uint_it(it1, a1), list_uint_it(it2,a2); !list_uint_end_p(it1); list_uint_next(it1), list_uint_next(it2)) { s += *list_uint_cref(it1) * *list_uint_cref(it2); } + g_result = s; } } @@ -99,6 +103,7 @@ static void test_rbtree(size_t n) if (p) s += *p; } + g_result = s; } } @@ -121,6 +126,7 @@ test_dict(unsigned long n) if (p) s += *p; } + g_result = s; } } @@ -161,6 +167,7 @@ test_dict_big(unsigned long n) if (p) s ++; } + g_result = s; } } diff --git a/bench/bench-qt.cpp b/bench/bench-qt.cpp index 4e938453..a064fce4 100644 --- a/bench/bench-qt.cpp +++ b/bench/bench-qt.cpp @@ -16,6 +16,8 @@ using namespace std; +unsigned long g_result; + static unsigned long long cputime (void) { @@ -60,6 +62,7 @@ static void test_list(size_t n) for (QLinkedList::const_iterator ci1 = a1.begin(), ci2 = a2.begin (); ci1 != a1.end(); ++ci1, ++ci2) { s += *ci1 * *ci2; } + g_result = s; } /********************************************************************************************/ @@ -76,6 +79,7 @@ static void test_array(size_t n) for(unsigned long i = 0; i < n; i++) { s += a1[i] * a2[i]; } + g_result = s; } /********************************************************************************************/ @@ -98,6 +102,7 @@ static void test_rbtree(size_t n) if (it != tree.end()) s += *it; } + g_result = s; } #endif @@ -119,6 +124,7 @@ test_dict1(unsigned long n) if (it != dict.end()) s += it.value(); } + g_result = s; } /********************************************************************************************/ @@ -139,6 +145,7 @@ test_dict2(unsigned long n) if (it != dict.end()) s += it.value(); } + g_result = s; } /********************************************************************************************/ @@ -177,7 +184,8 @@ test_dict_big(unsigned long n) QHash::iterator it = dict.find(s1); if (it != dict.end()) s ++; - } + } + g_result = s; } /********************************************************************************************/ diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index 0950b838..2e82c988 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -17,6 +17,8 @@ using namespace std; +unsigned long g_result; + static unsigned long long cputime (void) { @@ -61,6 +63,7 @@ static void test_list(size_t n) for (list::const_iterator ci1 = a1.begin(), ci2 = a2.begin (); ci1 != a1.end(); ++ci1, ++ci2) { s += *ci1 * *ci2; } + g_result = s; } /********************************************************************************************/ @@ -77,6 +80,7 @@ static void test_array(size_t n) for(unsigned long i = 0; i < n; i++) { s += a1[i] * a2[i]; } + g_result = s; } /********************************************************************************************/ @@ -96,6 +100,7 @@ static void test_rbtree(size_t n) if (it != tree.end()) s += *it; } + g_result = s; } /********************************************************************************************/ @@ -116,6 +121,7 @@ test_dict1(unsigned long n) if (it != dict.end()) s += it->second; } + g_result = s; } /********************************************************************************************/ @@ -136,6 +142,7 @@ test_dict2(unsigned long n) if (it != dict.end()) s += it->second; } + g_result = s; } /********************************************************************************************/ @@ -178,7 +185,8 @@ test_dict_big(unsigned long n) unordered_map::iterator it = dict.find(s1); if (it != dict.end()) s ++; - } + } + g_result = s; } /********************************************************************************************/