summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-09-24 17:14:29 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-09-24 17:14:29 +0000
commit550ebc9ab199b2dbd63e4c7e9c0bb539775246a2 (patch)
treeeeba95cbd77e86bf263f99c0538f4b1d36aacdd5 /legacy/eina/src/tests/eina_bench_hash.c
parent5ed8ea7e09f3e4808c556fbdf9e72479694c4c61 (diff)
Add hash and rbtree delete callback, cleanup the code and improve performance (hash as a new internal structure).
We still need a hash function for removing a node from the hash and destroying it at the same time. SVN revision: 36222
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c79
1 files changed, 28 insertions, 51 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index af2ea6032e..ee98ae0e34 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -67,6 +67,12 @@ _eina_bench_rbtree_key(const Eina_Bench_Rbtree *node, const char *key, int lengt
67} 67}
68 68
69static void 69static void
70_eina_bench_rbtree_free(Eina_Rbtree *node, __UNUSED__ void *data)
71{
72 free(node);
73}
74
75static void
70eina_bench_lookup_rbtree(int request) 76eina_bench_lookup_rbtree(int request)
71{ 77{
72 Eina_Rbtree *root = NULL; 78 Eina_Rbtree *root = NULL;
@@ -97,26 +103,17 @@ eina_bench_lookup_rbtree(int request)
97 tmp = eina_rbtree_inline_lookup(root, tmp_key, 10, EINA_RBTREE_CMP_KEY_CB(_eina_bench_rbtree_key), NULL); 103 tmp = eina_rbtree_inline_lookup(root, tmp_key, 10, EINA_RBTREE_CMP_KEY_CB(_eina_bench_rbtree_key), NULL);
98 } 104 }
99 105
100 while (root) 106 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL);
101 {
102 tmp = root;
103 root = eina_rbtree_inline_remove(root, root, EINA_RBTREE_CMP_NODE_CB(_eina_bench_rbtree_cmp), NULL);
104 free(tmp);
105 }
106} 107}
107 108
108static void 109static void
109eina_bench_lookup_superfast(int request) 110eina_bench_lookup_superfast(int request)
110{ 111{
111 Eina_Hash *hash = NULL; 112 Eina_Hash *hash = NULL;
112 Eina_Array *array = NULL;
113 int *tmp_val; 113 int *tmp_val;
114 Eina_Array_Iterator it;
115 unsigned int i; 114 unsigned int i;
116 115
117 array = eina_array_new(1000); 116 hash = eina_hash_string_superfast_new(free);
118
119 hash = eina_hash_string_superfast_new();
120 117
121 for (i = 0; i < (unsigned int) request; ++i) 118 for (i = 0; i < (unsigned int) request; ++i)
122 { 119 {
@@ -130,8 +127,6 @@ eina_bench_lookup_superfast(int request)
130 *tmp_val = i; 127 *tmp_val = i;
131 128
132 eina_hash_add(hash, tmp_key, tmp_val); 129 eina_hash_add(hash, tmp_key, tmp_val);
133
134 eina_array_push(array, tmp_val);
135 } 130 }
136 131
137 srand(time(NULL)); 132 srand(time(NULL));
@@ -146,25 +141,16 @@ eina_bench_lookup_superfast(int request)
146 } 141 }
147 142
148 eina_hash_free(hash); 143 eina_hash_free(hash);
149
150 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
151 free(tmp_val);
152
153 eina_array_free(array);
154} 144}
155 145
156static void 146static void
157eina_bench_lookup_djb2(int request) 147eina_bench_lookup_djb2(int request)
158{ 148{
159 Eina_Hash *hash = NULL; 149 Eina_Hash *hash = NULL;
160 Eina_Array *array = NULL;
161 int *tmp_val; 150 int *tmp_val;
162 Eina_Array_Iterator it;
163 unsigned int i; 151 unsigned int i;
164 152
165 array = eina_array_new(1000); 153 hash = eina_hash_string_djb2_new(free);
166
167 hash = eina_hash_string_djb2_new();
168 154
169 for (i = 0; i < (unsigned int) request; ++i) 155 for (i = 0; i < (unsigned int) request; ++i)
170 { 156 {
@@ -178,8 +164,6 @@ eina_bench_lookup_djb2(int request)
178 *tmp_val = i; 164 *tmp_val = i;
179 165
180 eina_hash_add(hash, tmp_key, tmp_val); 166 eina_hash_add(hash, tmp_key, tmp_val);
181
182 eina_array_push(array, tmp_val);
183 } 167 }
184 168
185 srand(time(NULL)); 169 srand(time(NULL));
@@ -194,41 +178,37 @@ eina_bench_lookup_djb2(int request)
194 } 178 }
195 179
196 eina_hash_free(hash); 180 eina_hash_free(hash);
197
198 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
199 free(tmp_val);
200
201 eina_array_free(array);
202} 181}
203 182
183typedef struct _Eina_Bench_DJB2 Eina_Bench_DJB2;
184struct _Eina_Bench_DJB2
185{
186 char *key;
187 int value;
188};
189
204static void 190static void
205eina_bench_lookup_djb2_inline(int request) 191eina_bench_lookup_djb2_inline(int request)
206{ 192{
207 Eina_Hash *hash = NULL; 193 Eina_Hash *hash = NULL;
208 Eina_Array *array = NULL; 194 Eina_Bench_DJB2 *elm;
209 int *tmp_val;
210 Eina_Array_Iterator it;
211 unsigned int i; 195 unsigned int i;
212 196
213 array = eina_array_new(1000); 197 hash = eina_hash_string_djb2_new(free);
214
215 hash = eina_hash_string_djb2_new();
216 198
217 for (i = 0; i < (unsigned int) request; ++i) 199 for (i = 0; i < (unsigned int) request; ++i)
218 { 200 {
219 char tmp_key[10];
220 int length; 201 int length;
221 202
222 tmp_val = malloc(sizeof (int)); 203 elm = malloc(sizeof (Eina_Bench_DJB2) + 10);
223 204 if (!elm) continue ;
224 if (!tmp_key || !tmp_val) continue ;
225 205
226 length = eina_convert_itoa(i, tmp_key) + 1; 206 elm->key = (char*) (elm + 1);
227 *tmp_val = i;
228 207
229 eina_hash_add_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length), tmp_val); 208 length = eina_convert_itoa(i, elm->key) + 1;
209 elm->value = i;
230 210
231 eina_array_push(array, tmp_val); 211 eina_hash_direct_add_by_hash(hash, elm->key, length, eina_hash_superfast(elm->key, length), elm);
232 } 212 }
233 213
234 srand(time(NULL)); 214 srand(time(NULL));
@@ -236,19 +216,14 @@ eina_bench_lookup_djb2_inline(int request)
236 for (i = 0; i < (unsigned int) request; ++i) 216 for (i = 0; i < (unsigned int) request; ++i)
237 { 217 {
238 char tmp_key[10]; 218 char tmp_key[10];
239 int length; 219 int length = 6;
240 220
241 length = eina_convert_itoa(rand() % request, tmp_key) + 1; 221 length = eina_convert_itoa(rand() % request, tmp_key) + 1;
242 222
243 tmp_val = eina_hash_find_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length)); 223 elm = eina_hash_find_by_hash(hash, tmp_key, length, eina_hash_superfast(tmp_key, length));
244 } 224 }
245 225
246 eina_hash_free(hash); 226 eina_hash_free(hash);
247
248 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
249 free(tmp_val);
250
251 eina_array_free(array);
252} 227}
253 228
254#ifdef EINA_BENCH_HAVE_GLIB 229#ifdef EINA_BENCH_HAVE_GLIB
@@ -401,8 +376,10 @@ void eina_bench_hash(Eina_Benchmark *bench)
401 eina_benchmark_register(bench, "ghash-lookup", EINA_BENCHMARK(eina_bench_lookup_ghash), 1000, 180000, 2500); 376 eina_benchmark_register(bench, "ghash-lookup", EINA_BENCHMARK(eina_bench_lookup_ghash), 1000, 180000, 2500);
402#endif 377#endif
403#ifdef EINA_BENCH_HAVE_EVAS 378#ifdef EINA_BENCH_HAVE_EVAS
379#if 0
404 eina_benchmark_register(bench, "evas-lookup", EINA_BENCHMARK(eina_bench_lookup_evas), 1000, 180000, 2500); 380 eina_benchmark_register(bench, "evas-lookup", EINA_BENCHMARK(eina_bench_lookup_evas), 1000, 180000, 2500);
405#endif 381#endif
382#endif
406#ifdef EINA_BENCH_HAVE_ECORE 383#ifdef EINA_BENCH_HAVE_ECORE
407 eina_benchmark_register(bench, "ecore-lookup", EINA_BENCHMARK(eina_bench_lookup_ecore), 1000, 180000, 2500); 384 eina_benchmark_register(bench, "ecore-lookup", EINA_BENCHMARK(eina_bench_lookup_ecore), 1000, 180000, 2500);
408#endif 385#endif