Enlightenment CVS committal Author : cedric Project : e17 Module : proto/eina
Dir : e17/proto/eina/src/tests Modified Files: eina_bench_hash.c Log Message: Benchmark inline version of djb2 hash function. =================================================================== RCS file: /cvs/e/e17/proto/eina/src/tests/eina_bench_hash.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- eina_bench_hash.c 6 Aug 2008 18:15:24 -0000 1.2 +++ eina_bench_hash.c 7 Aug 2008 09:13:24 -0000 1.3 @@ -26,7 +26,7 @@ #include "eina_bench.h" static void -eina_bench_insert_superfast(int request) +eina_bench_lookup_superfast(int request) { Eina_Hash *hash = NULL; Eina_Array *array = NULL; @@ -39,11 +39,11 @@ for (i = 0; i < (unsigned int) request; ++i) { - char *tmp_key = malloc(10); + char tmp_key[10]; tmp_val = malloc(sizeof (int)); - if (!tmp_key || !tmp_val) continue ; + if (!tmp_val) continue ; snprintf(tmp_key, 10, "%i", i); *tmp_val = i; @@ -51,46 +51,17 @@ eina_hash_add(hash, tmp_key, tmp_val); eina_array_append(array, tmp_val); - - free(tmp_key); } - eina_hash_free(hash); - - EINA_ARRAY_ITER_NEXT(array, i, tmp_val) - free(tmp_val); - - eina_array_free(array); -} - -static void -eina_bench_insert_djb2(int request) -{ - Eina_Hash *hash = NULL; - Eina_Array *array = NULL; - int *tmp_val; - unsigned int i; - - array = eina_array_new(1000); - - hash = eina_hash_string_djb2_new(); + srand(time(NULL)); for (i = 0; i < (unsigned int) request; ++i) { - char *tmp_key = malloc(10); - - tmp_val = malloc(sizeof (int)); - - if (!tmp_key || !tmp_val) continue ; - - snprintf(tmp_key, 10, "%i", i); - *tmp_val = i; - - eina_hash_add(hash, tmp_key, tmp_val); + char tmp_key[10]; - eina_array_append(array, tmp_val); + snprintf(tmp_key, 10, "%i", rand() % request); - free(tmp_key); + tmp_val = eina_hash_find(hash, tmp_key); } eina_hash_free(hash); @@ -102,7 +73,7 @@ } static void -eina_bench_lookup_superfast(int request) +eina_bench_lookup_djb2(int request) { Eina_Hash *hash = NULL; Eina_Array *array = NULL; @@ -111,15 +82,15 @@ array = eina_array_new(1000); - hash = eina_hash_string_superfast_new(); + hash = eina_hash_string_djb2_new(); for (i = 0; i < (unsigned int) request; ++i) { - char tmp_key[10]; + char *tmp_key[10]; tmp_val = malloc(sizeof (int)); - if (!tmp_val) continue ; + if (!tmp_key || !tmp_val) continue ; snprintf(tmp_key, 10, "%i", i); *tmp_val = i; @@ -149,7 +120,7 @@ } static void -eina_bench_lookup_djb2(int request) +eina_bench_lookup_djb2_inline(int request) { Eina_Hash *hash = NULL; Eina_Array *array = NULL; @@ -162,20 +133,19 @@ for (i = 0; i < (unsigned int) request; ++i) { - char *tmp_key = malloc(10); + char tmp_key[10]; + int length; tmp_val = malloc(sizeof (int)); if (!tmp_key || !tmp_val) continue ; - snprintf(tmp_key, 10, "%i", i); + length = snprintf(tmp_key, 10, "%i", i) + 1; *tmp_val = i; - eina_hash_add(hash, tmp_key, tmp_val); + eina_hash_add_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length), tmp_val); eina_array_append(array, tmp_val); - - free(tmp_key); } srand(time(NULL)); @@ -183,10 +153,11 @@ for (i = 0; i < (unsigned int) request; ++i) { char tmp_key[10]; + int length; - snprintf(tmp_key, 10, "%i", rand() % request); + length = snprintf(tmp_key, 10, "%i", rand() % request) + 1; - tmp_val = eina_hash_find(hash, tmp_key); + tmp_val = eina_hash_find_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length)); } eina_hash_free(hash); @@ -199,8 +170,7 @@ void eina_bench_hash(Eina_Bench *bench) { - eina_bench_register(bench, "superfast-insert", EINA_BENCH(eina_bench_insert_superfast), 1000, 180000, 2500); - eina_bench_register(bench, "djb2-insert", EINA_BENCH(eina_bench_insert_djb2), 1000, 180000, 2500); eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500); eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500); + eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500); } ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs