summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-08-28 16:33:40 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-08-28 16:33:40 +0000
commit3e562ccfc294aedd93ef2592550b59b2f16d9613 (patch)
tree2bba789b977b509d56d106df08ea65ae16905d1b /legacy/eina/src/tests/eina_bench_hash.c
parentf6bcf421ce7d6ae1b3f1d1eb5abd6d345cc1e961 (diff)
Add a context to the callback.
SVN revision: 35719
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c68
1 files changed, 42 insertions, 26 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index 72f3732bce..febb4b1059 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -32,53 +32,68 @@
32#include "eina_hash.h" 32#include "eina_hash.h"
33#include "eina_array.h" 33#include "eina_array.h"
34#include "eina_bench.h" 34#include "eina_bench.h"
35#include "eina_rbtree.h"
35 36
36static void 37typedef struct _Eina_Bench_Rbtree Eina_Bench_Rbtree;
37eina_bench_lookup_rbtree(int request) 38struct _Eina_Bench_Rbtree
38{ 39{
39 Eina_Hash *hash = NULL; 40 Eina_Rbtree node;
40 Eina_Array *array = NULL; 41 char key[10];
41 int *tmp_val; 42 int value;
42 Eina_Array_Iterator it; 43};
43 unsigned int i;
44 44
45 array = eina_array_new(1000); 45static Eina_Rbtree_Direction
46_eina_bench_rbtree_cmp(const Eina_Bench_Rbtree *left, const Eina_Bench_Rbtree *right, __UNUSED__ void *data)
47{
48 if (!left) return EINA_RBTREE_RIGHT;
49 if (!right) return EINA_RBTREE_LEFT;
46 50
47 hash = eina_hash_string_superfast_new(); 51 return strcmp(left->key, right->key) < 0 ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT;
52}
48 53
49 for (i = 0; i < (unsigned int) request; ++i) 54static inline int
50 { 55_eina_bench_rbtree_key(const Eina_Bench_Rbtree *node, const char *key, int length, __UNUSED__ void *data)
51 char tmp_key[10]; 56{
57 return strncmp(node->key, key, length);
58}
52 59
53 tmp_val = malloc(sizeof (int)); 60static void
61eina_bench_lookup_rbtree(int request)
62{
63 Eina_Rbtree *root = NULL;
64 Eina_Rbtree *tmp;
65 int i;
54 66
55 if (!tmp_val) continue ; 67 for (i = 0; i < request; ++i)
68 {
69 Eina_Bench_Rbtree *tmp;
56 70
57 snprintf(tmp_key, 10, "%i", i); 71 tmp = malloc(sizeof (Eina_Bench_Rbtree));
58 *tmp_val = i; 72 if (!tmp) continue ;
59 73
60 eina_hash_add(hash, tmp_key, tmp_val); 74 tmp->value = i;
75 snprintf(tmp->key, 10, "%i", i);
61 76
62 eina_array_push(array, tmp_val); 77 root = eina_rbtree_inline_insert(root, &tmp->node, EINA_RBTREE_CMP_NODE_CB(_eina_bench_rbtree_cmp), NULL);
63 } 78 }
64 79
65 srand(time(NULL)); 80 srand(time(NULL));
66 81
67 for (i = 0; i < (unsigned int) request; ++i) 82 for (i = 0; i < request; ++i)
68 { 83 {
69 char tmp_key[10]; 84 char tmp_key[10];
70 85
71 snprintf(tmp_key, 10, "%i", rand() % request); 86 snprintf(tmp_key, 10, "%i", rand() % request);
72 87
73 tmp_val = eina_hash_find(hash, tmp_key); 88 tmp = eina_rbtree_inline_lookup(root, tmp_key, 10, EINA_RBTREE_CMP_KEY_CB(_eina_bench_rbtree_key), NULL);
74 } 89 }
75 90
76 eina_hash_free(hash); 91 while (root)
77 92 {
78 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) 93 tmp = root;
79 free(tmp_val); 94 root = eina_rbtree_inline_remove(root, root, EINA_RBTREE_CMP_NODE_CB(_eina_bench_rbtree_cmp), NULL);
80 95 free(tmp);
81 eina_array_free(array); 96 }
82} 97}
83 98
84static void 99static void
@@ -277,6 +292,7 @@ void eina_bench_hash(Eina_Bench *bench)
277 eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500); 292 eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500);
278 eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500); 293 eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500);
279 eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500); 294 eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500);
295 eina_bench_register(bench, "rbtree", EINA_BENCH(eina_bench_lookup_rbtree), 1000, 180000, 2500);
280#ifdef EINA_BENCH_HAVE_GLIB 296#ifdef EINA_BENCH_HAVE_GLIB
281 eina_bench_register(bench, "ghash-lookup", EINA_BENCH(eina_bench_lookup_ghash), 1000, 180000, 2500); 297 eina_bench_register(bench, "ghash-lookup", EINA_BENCH(eina_bench_lookup_ghash), 1000, 180000, 2500);
282#endif 298#endif