Add dictionnary test.
This commit is contained in:
1 parent
7e651907c0
commit
660ae3dd5b
2 files changed
+50
-3
No files matched your search
+2
-1
@@ -116,10 +116,11 @@ bench-tommyds:
|
|||||||
if test -n "$${TOMMYDS}" ; then make bench-tommyds0 ; else echo "Nothing to be done." ; fi
|
if test -n "$${TOMMYDS}" ; then make bench-tommyds0 ; else echo "Nothing to be done." ; fi
|
||||||
|
|
||||||
bench-tommyds0:
|
bench-tommyds0:
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${TOMMYDS}" bench-tommyds.c $${TOMMYDS}/tommyds/tommyarray.c $${TOMMYDS}/tommyds/tommylist.c $${TOMMYDS}/tommyds/tommytree.c -o bench-tommyds.exe
|
$(CC) $(CFLAGS) $(CPPFLAGS) -I "$${TOMMYDS}" bench-tommyds.c $${TOMMYDS}/tommyds/tommyarray.c $${TOMMYDS}/tommyds/tommylist.c $${TOMMYDS}/tommyds/tommytree.c $${TOMMYDS}/tommyds/tommyhashlin.c -o bench-tommyds.exe
|
||||||
@./bench-tommyds.exe 10
|
@./bench-tommyds.exe 10
|
||||||
@./bench-tommyds.exe 20
|
@./bench-tommyds.exe 20
|
||||||
@./bench-tommyds.exe 30
|
@./bench-tommyds.exe 30
|
||||||
|
@./bench-tommyds.exe 40
|
||||||
|
|
||||||
bench-plain:
|
bench-plain:
|
||||||
$(CC) $(CFLAGS) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe
|
$(CC) $(CFLAGS) $(CPPFLAGS) bench-plain-c.c -o bench-plain-c.exe
|
||||||
|
|||||||
+48
-2
@@ -109,6 +109,52 @@ static void test_rbtree(size_t n)
|
|||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
|
struct hash_i_node_s {
|
||||||
|
unsigned long key;
|
||||||
|
unsigned long value;
|
||||||
|
tommy_node node;
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline size_t hash_func (const unsigned long key)
|
||||||
|
{
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int equal_func(const void* arg, const void *obj_p)
|
||||||
|
{
|
||||||
|
const struct hash_i_node_s *obj = obj_p;
|
||||||
|
const unsigned long *key = arg;
|
||||||
|
return *key != obj->key;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_dict(unsigned long n)
|
||||||
|
{
|
||||||
|
tommy_hashlin dict;
|
||||||
|
tommy_hashlin_init(&dict);
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
struct hash_i_node_s *obj = malloc(sizeof (struct hash_i_node_s));
|
||||||
|
if(!obj) abort();
|
||||||
|
obj->key = rand_get();
|
||||||
|
obj->value = rand_get();
|
||||||
|
tommy_hashlin_insert(&dict, &obj->node, obj, hash_func(obj->key));
|
||||||
|
}
|
||||||
|
rand_init();
|
||||||
|
unsigned int s = 0;
|
||||||
|
for (size_t i = 0; i < n; i++) {
|
||||||
|
unsigned long key = rand_get();
|
||||||
|
struct hash_i_node_s *obj = tommy_hashlin_search(&dict, &equal_func,
|
||||||
|
&key,
|
||||||
|
hash_func(key));
|
||||||
|
if (obj)
|
||||||
|
s += obj->value;
|
||||||
|
}
|
||||||
|
g_result = s;
|
||||||
|
tommy_hashlin_done(&dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************************************/
|
||||||
|
|
||||||
int main(int argc, const char *argv[])
|
int main(int argc, const char *argv[])
|
||||||
{
|
{
|
||||||
int n = (argc > 1) ? atoi(argv[1]) : 0;
|
int n = (argc > 1) ? atoi(argv[1]) : 0;
|
||||||
@@ -118,9 +164,9 @@ int main(int argc, const char *argv[])
|
|||||||
test_function("Array time", 100000000, test_array);
|
test_function("Array time", 100000000, test_array);
|
||||||
if (n == 30)
|
if (n == 30)
|
||||||
test_function("Rbtree time", 1000000, test_rbtree);
|
test_function("Rbtree time", 1000000, test_rbtree);
|
||||||
/*if (n == 40)
|
if (n == 40)
|
||||||
test_function("Dict time", 1000000, test_dict);
|
test_function("Dict time", 1000000, test_dict);
|
||||||
if (n == 41)
|
/*if (n == 41)
|
||||||
test_function("DictB time", 1000000, test_dict_big);
|
test_function("DictB time", 1000000, test_dict_big);
|
||||||
if (n == 50)
|
if (n == 50)
|
||||||
test_function("Sort time", 10000000, test_sort);*/
|
test_function("Sort time", 10000000, test_sort);*/
|
||||||
|
|||||||
Reference in new issue
Block a user