Code factorisation.

This commit is contained in:
Patrick Pelissier committed 2017-07-08 17:21:56 +02:00
1 parent de45d61966
commit 5da62a898d
7 files changed
+1 -39

No files matched your search

-6
View File
@@ -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();
-6
View File
@@ -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);
-3
View File
@@ -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, "");
-8
View File
@@ -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() );
-7
View File
@@ -23,7 +23,6 @@ using namespace std;
static void test_list(size_t n)
{
rand_init();
QLinkedList<unsigned int> 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<unsigned int> 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<unsigned long, QHashDummyValue> 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<unsigned long, unsigned long> 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<unsigned long, unsigned long> 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<char_array_s, char_array_s> 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<float> a1;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
-9
View File
@@ -26,7 +26,6 @@ using namespace std;
static void test_list(size_t n)
{
rand_init();
list<unsigned int> 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<unsigned int> 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<unsigned long> 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<unsigned long, unsigned long> 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<unsigned long, unsigned long> 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<char_array_s, char_array_s> 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<string, string> 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<string, string> 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<float> a1;
for(size_t i = 0; i < n; i++) {
a1.push_back(rand_get() );
+1
View File
@@ -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();