From 5da62a898d05b7183db182e487366023affb57c4 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 8 Jul 2017 17:21:56 +0200 Subject: [PATCH] Code factorisation. --- bench/bench-glib.c | 6 ------ bench/bench-klib.c | 6 ------ bench/bench-libdynamic.c | 3 --- bench/bench-mlib.c | 8 -------- bench/bench-qt.cpp | 7 ------- bench/bench-stl.cpp | 9 --------- bench/common.h | 1 + 7 files changed, 1 insertion(+), 39 deletions(-) diff --git a/bench/bench-glib.c b/bench/bench-glib.c index f521ff47..e1dbb87d 100644 --- a/bench/bench-glib.c +++ b/bench/bench-glib.c @@ -16,7 +16,6 @@ static void test_array(size_t n) { - rand_init(); GArray *a1, *a2; a1 = g_array_new (FALSE, FALSE, sizeof (unsigned int)); a2 = g_array_new (FALSE, FALSE, sizeof (unsigned int)); @@ -39,7 +38,6 @@ static void test_array(size_t n) static void test_list (size_t n) { - rand_init(); GSList *a1 = NULL, *a2 = NULL; for(size_t i = 0; i < n; i++) { @@ -68,7 +66,6 @@ static int compare(gconstpointer a, gconstpointer b, gpointer user_data) static void test_rbtree(size_t n) { - rand_init(); GTree *tree = g_tree_new_full(compare, NULL, free, free); for (size_t i = 0; i < n; i++) { // NOTE: unsigned long are not designed to work with GPOINTER_TO_INT according to documentation. @@ -105,7 +102,6 @@ static gboolean equal_func(gconstpointer a, gconstpointer b) static void test_dict(unsigned long n) { - rand_init(); GHashTable *dict = g_hash_table_new_full(hash_func, equal_func, free, free); for (size_t i = 0; i < n; i++) { unsigned long *key = malloc(sizeof(unsigned long)); @@ -149,7 +145,6 @@ static guint char_hash(gconstpointer a) static void test_dict_big(unsigned long n) { - rand_init(); GHashTable *dict = g_hash_table_new_full(char_hash, char_equal, free, free); for (size_t i = 0; i < n; i++) { char_array_t *key = malloc (sizeof (char_array_t)); @@ -182,7 +177,6 @@ static gint cmp_float(gconstpointer a, static void test_sort(size_t n) { - rand_init(); GArray *a1 = g_array_new (FALSE, FALSE, sizeof (float)); for(size_t i = 0; i < n; i++) { float v = rand_get(); diff --git a/bench/bench-klib.c b/bench/bench-klib.c index 98e4f462..214c3d9f 100644 --- a/bench/bench-klib.c +++ b/bench/bench-klib.c @@ -19,7 +19,6 @@ static void test_array(size_t n) { - rand_init(); kvec_t(unsigned int) a1, a2; kv_init(a1); @@ -46,7 +45,6 @@ KLIST_INIT(list_uint, unsigned int, uint_free) static void test_list (size_t n) { - rand_init(); klist_t(list_uint) *a1, *a2; a1 = kl_init(list_uint); a2 = kl_init(list_uint); @@ -76,7 +74,6 @@ KBTREE_INIT(kTree, unsigned long, my_cmp) static void test_rbtree(size_t n) { - rand_init(); kbtree_t(kTree) *tree; tree = kb_init(kTree, KB_DEFAULT_SIZE/2); @@ -106,7 +103,6 @@ KHASH_INIT(iun, unsigned long, unsigned long, 1, hash_func, hash_eq) static void test_dict(unsigned long n) { - rand_init(); khash_t(iun) *dict = kh_init(iun); for (size_t i = 0; i < n; i++) { @@ -146,7 +142,6 @@ KHASH_INIT(iub, char_array_t, char_array_t, 1, char_hash, char_equal_p) static void test_dict_big(unsigned long n) { - rand_init(); khash_t(iub) *dict = kh_init(iub); for (size_t i = 0; i < n; i++) { @@ -179,7 +174,6 @@ KSORT_INIT_GENERIC(float) static void test_sort(size_t n) { - rand_init(); kvec_t(float) a1; kv_init(a1); diff --git a/bench/bench-libdynamic.c b/bench/bench-libdynamic.c index 75411adb..a159e40f 100644 --- a/bench/bench-libdynamic.c +++ b/bench/bench-libdynamic.c @@ -17,7 +17,6 @@ static void test_array(size_t n) { - rand_init(); vector a1, a2; vector_construct(&a1, sizeof(unsigned int)); @@ -69,7 +68,6 @@ struct map_element static void test_dict(unsigned long n) { - rand_init(); map dict; map_construct(&dict, sizeof(map_element), (map_element[]) {{.key = -1}}, set_func); @@ -121,7 +119,6 @@ struct big_map_element static void test_dict_big(unsigned long n) { - rand_init(); map dict; big_map_element empty; strcpy(empty.key, ""); diff --git a/bench/bench-mlib.c b/bench/bench-mlib.c index 73d4c7f4..bba05f3b 100644 --- a/bench/bench-mlib.c +++ b/bench/bench-mlib.c @@ -23,7 +23,6 @@ ARRAY_DEF(uint, unsigned int) static void test_array(size_t n) { - rand_init(); M_LET(a1, a2, ARRAY_OPLIST(uint)) { for(size_t i = 0; i < n; i++) { array_uint_push_back(a1, rand_get() ); @@ -48,7 +47,6 @@ LIST_DEF(uint, unsigned int) static void test_list (size_t n) { - rand_init(); #ifdef USE_MEMPOOL mempool_list_uint_init(list_mpool); #endif @@ -82,7 +80,6 @@ static void test_rbtree(size_t n) #ifdef USE_MEMPOOL mempool_rbtree_ulong_init(rbtree_mpool); #endif - rand_init(); M_LET(tree, RBTREE_OPLIST(ulong)) { for (size_t i = 0; i < n; i++) { rbtree_ulong_push(tree, rand_get()); @@ -115,7 +112,6 @@ test_dict(unsigned long n) #ifdef USE_MEMPOOL mempool_list_dict_pair_ulong_init(dict_mpool); #endif - rand_init(); M_LET(dict, DICT_OPLIST(ulong)) { for (size_t i = 0; i < n; i++) { dict_ulong_set_at(dict, rand_get(), rand_get() ); @@ -151,7 +147,6 @@ DICT_OA_DEF2(oa_ulong, unsigned long, M_OPEXTEND(M_DEFAULT_OPLIST, OOR_EQUAL(oor static void test_dict_oa(unsigned long n) { - rand_init(); M_LET(dict, DICT_OPLIST(oa_ulong)) { for (size_t i = 0; i < n; i++) { dict_oa_ulong_set_at(dict, rand_get(), rand_get() ); @@ -191,7 +186,6 @@ test_dict_big(unsigned long n) #ifdef USE_MEMPOOL mempool_list_dict_pair_char_init(dict_mpool2); #endif - rand_init(); M_LET(dict, DICT_OPLIST(char)) { for (size_t i = 0; i < n; i++) { char_array_t s1, s2; @@ -229,7 +223,6 @@ test_dict_str(unsigned long n) #ifdef USE_MEMPOOL mempool_list_dict_pair_str_init(dict_mpool3); #endif - rand_init(); M_LET(s1, s2, STRING_OPLIST) M_LET(dict, DICT_OPLIST(str)) { for (size_t i = 0; i < n; i++) { @@ -259,7 +252,6 @@ ALGO_DEF(afloat, ARRAY_OPLIST(float)) static void test_sort(size_t n) { - rand_init(); M_LET(a1, ARRAY_OPLIST(float)) { for(size_t i = 0; i < n; i++) { array_float_push_back(a1, rand_get() ); diff --git a/bench/bench-qt.cpp b/bench/bench-qt.cpp index f5cd911a..03cbe020 100644 --- a/bench/bench-qt.cpp +++ b/bench/bench-qt.cpp @@ -23,7 +23,6 @@ using namespace std; static void test_list(size_t n) { - rand_init(); QLinkedList a1, a2; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); @@ -40,7 +39,6 @@ static void test_list(size_t n) static void test_array(size_t n) { - rand_init(); QVector a1, a2; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); @@ -59,7 +57,6 @@ static void test_array(size_t n) which is a set with total ordering within Qt. So we have to fake it. */ static void test_rbtree(size_t n) { - rand_init(); QMap tree; for (size_t i = 0; i < n; i++) { @@ -80,7 +77,6 @@ static void test_rbtree(size_t n) static void test_dict1(unsigned long n) { - rand_init(); QMap dict; for (size_t i = 0; i < n; i++) { @@ -101,7 +97,6 @@ test_dict1(unsigned long n) static void test_dict2(unsigned long n) { - rand_init(); QHash dict; for (size_t i = 0; i < n; i++) { @@ -136,7 +131,6 @@ uint qHash(const char_array_s &k) static void test_dict_big(unsigned long n) { - rand_init(); QHash dict; for (size_t i = 0; i < n; i++) { @@ -161,7 +155,6 @@ test_dict_big(unsigned long n) static void test_sort(size_t n) { - rand_init(); QVector a1; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); diff --git a/bench/bench-stl.cpp b/bench/bench-stl.cpp index 75d577e4..e3ab3fc7 100644 --- a/bench/bench-stl.cpp +++ b/bench/bench-stl.cpp @@ -26,7 +26,6 @@ using namespace std; static void test_list(size_t n) { - rand_init(); list a1, a2; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); @@ -43,7 +42,6 @@ static void test_list(size_t n) static void test_array(size_t n) { - rand_init(); vector a1, a2; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); @@ -60,7 +58,6 @@ static void test_array(size_t n) static void test_rbtree(size_t n) { - rand_init(); set tree; for (size_t i = 0; i < n; i++) { @@ -81,7 +78,6 @@ static void test_rbtree(size_t n) static void test_dict1(unsigned long n) { - rand_init(); map dict; for (size_t i = 0; i < n; i++) { @@ -102,7 +98,6 @@ test_dict1(unsigned long n) static void test_dict2(unsigned long n) { - rand_init(); unordered_map dict; for (size_t i = 0; i < n; i++) { @@ -141,7 +136,6 @@ namespace std { static void test_dict_big(unsigned long n) { - rand_init(); unordered_map dict; for (size_t i = 0; i < n; i++) { @@ -166,7 +160,6 @@ test_dict_big(unsigned long n) static void test_dict_str(unsigned long n) { - rand_init(); unordered_map dict; for (size_t i = 0; i < n; i++) { @@ -188,7 +181,6 @@ test_dict_str(unsigned long n) static void test_dict_str2(unsigned long n) { - rand_init(); map dict; for (size_t i = 0; i < n; i++) { @@ -211,7 +203,6 @@ test_dict_str2(unsigned long n) static void test_sort(size_t n) { - rand_init(); vector a1; for(size_t i = 0; i < n; i++) { a1.push_back(rand_get() ); diff --git a/bench/common.h b/bench/common.h index c53d6840..9e9d3c3b 100644 --- a/bench/common.h +++ b/bench/common.h @@ -23,6 +23,7 @@ static void test_function(const char str[], size_t n, void (*func)(size_t)) { unsigned long long start, end; // (*func)(n); + rand_init(); start = cputime(); (*func)(n); end = cputime();