summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-07-28 02:37:05 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-07-28 02:37:05 +0000
commitddc6ba2c2a8386a0d87e3a2aea318cb77eef30bd (patch)
tree27a489ed763bf22239b2d4fca93063213b8001bd /legacy/eina/src/tests/eina_bench_hash.c
parentc4da05607d5afdf472f85d036e1af6aab2f047a5 (diff)
uncrustify eina.
SVN revision: 50573
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c256
1 files changed, 149 insertions, 107 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index 686ab924c2..93bb69e993 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -47,16 +47,25 @@ struct _Eina_Bench_Rbtree
47}; 47};
48 48
49static Eina_Rbtree_Direction 49static Eina_Rbtree_Direction
50_eina_bench_rbtree_cmp(const Eina_Bench_Rbtree *left, const Eina_Bench_Rbtree *right, __UNUSED__ void *data) 50_eina_bench_rbtree_cmp(const Eina_Bench_Rbtree *left,
51 const Eina_Bench_Rbtree *right,
52 __UNUSED__ void *data)
51{ 53{
52 if (!left) return EINA_RBTREE_RIGHT; 54 if (!left)
53 if (!right) return EINA_RBTREE_LEFT; 55 return EINA_RBTREE_RIGHT;
54 56
55 return strcmp(left->key, right->key) < 0 ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT; 57 if (!right)
58 return EINA_RBTREE_LEFT;
59
60 return strcmp(left->key,
61 right->key) < 0 ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT;
56} 62}
57 63
58static inline int 64static inline int
59_eina_bench_rbtree_key(const Eina_Bench_Rbtree *node, const char *key, int length, __UNUSED__ void *data) 65_eina_bench_rbtree_key(const Eina_Bench_Rbtree *node,
66 const char *key,
67 int length,
68 __UNUSED__ void *data)
60{ 69{
61 return strncmp(node->key, key, length); 70 return strncmp(node->key, key, length);
62} 71}
@@ -76,29 +85,39 @@ eina_bench_lookup_rbtree(int request)
76 85
77 for (i = 0; i < request; ++i) 86 for (i = 0; i < request; ++i)
78 { 87 {
79 Eina_Bench_Rbtree *tmp; 88 Eina_Bench_Rbtree *tmp;
80 89
81 tmp = malloc(sizeof (Eina_Bench_Rbtree)); 90 tmp = malloc(sizeof (Eina_Bench_Rbtree));
82 if (!tmp) continue ; 91 if (!tmp)
92 continue;
83 93
84 tmp->value = i; 94 tmp->value = i;
85 eina_convert_itoa(i, tmp->key); 95 eina_convert_itoa(i, tmp->key);
86 96
87 root = eina_rbtree_inline_insert(root, &tmp->node, EINA_RBTREE_CMP_NODE_CB(_eina_bench_rbtree_cmp), NULL); 97 root = eina_rbtree_inline_insert(root,
98 &tmp->node,
99 EINA_RBTREE_CMP_NODE_CB(
100 _eina_bench_rbtree_cmp),
101 NULL);
88 } 102 }
89 103
90 srand(time(NULL)); 104 srand(time(NULL));
91 105
92 for (j = 0; j < 200; ++j) 106 for (j = 0; j < 200; ++j)
93 for (i = 0; i < request; ++i) 107 for (i = 0; i < request; ++i)
94 { 108 {
95 Eina_Rbtree *tmp; 109 Eina_Rbtree *tmp;
96 char tmp_key[10]; 110 char tmp_key[10];
97 111
98 eina_convert_itoa(rand() % request, tmp_key); 112 eina_convert_itoa(rand() % request, tmp_key);
99 113
100 tmp = eina_rbtree_inline_lookup(root, tmp_key, 10, EINA_RBTREE_CMP_KEY_CB(_eina_bench_rbtree_key), NULL); 114 tmp = eina_rbtree_inline_lookup(root,
101 } 115 tmp_key,
116 10,
117 EINA_RBTREE_CMP_KEY_CB(
118 _eina_bench_rbtree_key),
119 NULL);
120 }
102 121
103 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL); 122 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL);
104} 123}
@@ -113,30 +132,31 @@ eina_bench_lookup_superfast(int request)
113 132
114 hash = eina_hash_string_superfast_new(free); 133 hash = eina_hash_string_superfast_new(free);
115 134
116 for (i = 0; i < (unsigned int) request; ++i) 135 for (i = 0; i < (unsigned int)request; ++i)
117 { 136 {
118 char tmp_key[10]; 137 char tmp_key[10];
119 138
120 tmp_val = malloc(sizeof (int)); 139 tmp_val = malloc(sizeof (int));
121 140
122 if (!tmp_val) continue ; 141 if (!tmp_val)
142 continue;
123 143
124 eina_convert_itoa(i, tmp_key); 144 eina_convert_itoa(i, tmp_key);
125 *tmp_val = i; 145 *tmp_val = i;
126 146
127 eina_hash_add(hash, tmp_key, tmp_val); 147 eina_hash_add(hash, tmp_key, tmp_val);
128 } 148 }
129 149
130 srand(time(NULL)); 150 srand(time(NULL));
131 151
132 for (j = 0; j < 200; ++j) 152 for (j = 0; j < 200; ++j)
133 for (i = 0; i < (unsigned int) request; ++i) 153 for (i = 0; i < (unsigned int)request; ++i)
134 { 154 {
135 char tmp_key[10]; 155 char tmp_key[10];
136 156
137 eina_convert_itoa(rand() % request, tmp_key); 157 eina_convert_itoa(rand() % request, tmp_key);
138 tmp_val = eina_hash_find(hash, tmp_key); 158 tmp_val = eina_hash_find(hash, tmp_key);
139 } 159 }
140 160
141 eina_hash_free(hash); 161 eina_hash_free(hash);
142} 162}
@@ -151,31 +171,32 @@ eina_bench_lookup_djb2(int request)
151 171
152 hash = eina_hash_string_djb2_new(free); 172 hash = eina_hash_string_djb2_new(free);
153 173
154 for (i = 0; i < (unsigned int) request; ++i) 174 for (i = 0; i < (unsigned int)request; ++i)
155 { 175 {
156 char tmp_key[10]; 176 char tmp_key[10];
157 177
158 tmp_val = malloc(sizeof (int)); 178 tmp_val = malloc(sizeof (int));
159 179
160 if (!tmp_val) continue ; 180 if (!tmp_val)
181 continue;
161 182
162 eina_convert_itoa(i, tmp_key); 183 eina_convert_itoa(i, tmp_key);
163 *tmp_val = i; 184 *tmp_val = i;
164 185
165 eina_hash_add(hash, tmp_key, tmp_val); 186 eina_hash_add(hash, tmp_key, tmp_val);
166 } 187 }
167 188
168 srand(time(NULL)); 189 srand(time(NULL));
169 190
170 for (j = 0; j < 200; ++j) 191 for (j = 0; j < 200; ++j)
171 for (i = 0; i < (unsigned int) request; ++i) 192 for (i = 0; i < (unsigned int)request; ++i)
172 { 193 {
173 char tmp_key[10]; 194 char tmp_key[10];
174 195
175 eina_convert_itoa(rand() % request, tmp_key); 196 eina_convert_itoa(rand() % request, tmp_key);
176 197
177 tmp_val = eina_hash_find(hash, tmp_key); 198 tmp_val = eina_hash_find(hash, tmp_key);
178 } 199 }
179 200
180 eina_hash_free(hash); 201 eina_hash_free(hash);
181} 202}
@@ -197,33 +218,37 @@ eina_bench_lookup_djb2_inline(int request)
197 218
198 hash = eina_hash_string_djb2_new(free); 219 hash = eina_hash_string_djb2_new(free);
199 220
200 for (i = 0; i < (unsigned int) request; ++i) 221 for (i = 0; i < (unsigned int)request; ++i)
201 { 222 {
202 int length; 223 int length;
203 224
204 elm = malloc(sizeof (Eina_Bench_DJB2) + 10); 225 elm = malloc(sizeof (Eina_Bench_DJB2) + 10);
205 if (!elm) continue ; 226 if (!elm)
227 continue;
206 228
207 elm->key = (char*) (elm + 1); 229 elm->key = (char *)(elm + 1);
208 230
209 length = eina_convert_itoa(i, elm->key) + 1; 231 length = eina_convert_itoa(i, elm->key) + 1;
210 elm->value = i; 232 elm->value = i;
211 233
212 eina_hash_direct_add_by_hash(hash, elm->key, length, eina_hash_djb2(elm->key, length), elm); 234 eina_hash_direct_add_by_hash(hash, elm->key, length,
235 eina_hash_djb2(elm->key, length), elm);
213 } 236 }
214 237
215 srand(time(NULL)); 238 srand(time(NULL));
216 239
217 for (j = 0; j < 200; ++j) 240 for (j = 0; j < 200; ++j)
218 for (i = 0; i < (unsigned int) request; ++i) 241 for (i = 0; i < (unsigned int)request; ++i)
219 { 242 {
220 char tmp_key[10]; 243 char tmp_key[10];
221 int length = 6; 244 int length = 6;
222 245
223 length = eina_convert_itoa(rand() % request, tmp_key) + 1; 246 length = eina_convert_itoa(rand() % request, tmp_key) + 1;
224 247
225 elm = eina_hash_find_by_hash(hash, tmp_key, length, eina_hash_djb2(tmp_key, length)); 248 elm =
226 } 249 eina_hash_find_by_hash(hash, tmp_key, length,
250 eina_hash_djb2(tmp_key, length));
251 }
227 252
228 eina_hash_free(hash); 253 eina_hash_free(hash);
229} 254}
@@ -246,30 +271,31 @@ eina_bench_lookup_ghash(int request)
246 271
247 hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free); 272 hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
248 273
249 for (i = 0; i < (unsigned int) request; ++i) 274 for (i = 0; i < (unsigned int)request; ++i)
250 { 275 {
251 elm = malloc(sizeof (Eina_Bench_Glib) + 10); 276 elm = malloc(sizeof (Eina_Bench_Glib) + 10);
252 if (!elm) continue ; 277 if (!elm)
278 continue;
253 279
254 elm->key = (char*) (elm + 1); 280 elm->key = (char *)(elm + 1);
255 281
256 eina_convert_itoa(i, elm->key); 282 eina_convert_itoa(i, elm->key);
257 elm->value = i; 283 elm->value = i;
258 284
259 g_hash_table_insert(hash, elm->key, elm); 285 g_hash_table_insert(hash, elm->key, elm);
260 } 286 }
261 287
262 srand(time(NULL)); 288 srand(time(NULL));
263 289
264 for (j = 0; j < 200; ++j) 290 for (j = 0; j < 200; ++j)
265 for (i = 0; i < (unsigned int) request; ++i) 291 for (i = 0; i < (unsigned int)request; ++i)
266 { 292 {
267 char tmp_key[10]; 293 char tmp_key[10];
268 294
269 eina_convert_itoa(rand() % request, tmp_key); 295 eina_convert_itoa(rand() % request, tmp_key);
270 296
271 elm = g_hash_table_lookup(hash, tmp_key); 297 elm = g_hash_table_lookup(hash, tmp_key);
272 } 298 }
273 299
274 g_hash_table_destroy(hash); 300 g_hash_table_destroy(hash);
275} 301}
@@ -287,38 +313,39 @@ eina_bench_lookup_evas(int request)
287 313
288 array = eina_array_new(1000); 314 array = eina_array_new(1000);
289 315
290 for (i = 0; i < (unsigned int) request; ++i) 316 for (i = 0; i < (unsigned int)request; ++i)
291 { 317 {
292 char tmp_key[10]; 318 char tmp_key[10];
293 319
294 tmp_val = malloc(sizeof (int)); 320 tmp_val = malloc(sizeof (int));
295 321
296 if (!tmp_val) continue ; 322 if (!tmp_val)
323 continue;
297 324
298 eina_convert_itoa(i, tmp_key); 325 eina_convert_itoa(i, tmp_key);
299 *tmp_val = i; 326 *tmp_val = i;
300 327
301 hash = evas_hash_add(hash, tmp_key, tmp_val); 328 hash = evas_hash_add(hash, tmp_key, tmp_val);
302 329
303 eina_array_push(array, tmp_val); 330 eina_array_push(array, tmp_val);
304 } 331 }
305 332
306 srand(time(NULL)); 333 srand(time(NULL));
307 334
308 for (j = 0; j < 200; ++j) 335 for (j = 0; j < 200; ++j)
309 for (i = 0; i < (unsigned int) request; ++i) 336 for (i = 0; i < (unsigned int)request; ++i)
310 { 337 {
311 char tmp_key[10]; 338 char tmp_key[10];
312 339
313 eina_convert_itoa(rand() % request, tmp_key); 340 eina_convert_itoa(rand() % request, tmp_key);
314 341
315 tmp_val = evas_hash_find(hash, tmp_key); 342 tmp_val = evas_hash_find(hash, tmp_key);
316 } 343 }
317 344
318 evas_hash_free(hash); 345 evas_hash_free(hash);
319 346
320 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it) 347 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
321 free(tmp_val); 348 free(tmp_val);
322 349
323 eina_array_free(array); 350 eina_array_free(array);
324} 351}
@@ -343,42 +370,57 @@ eina_bench_lookup_ecore(int request)
343 ecore_hash_free_key_cb_set(hash, NULL); 370 ecore_hash_free_key_cb_set(hash, NULL);
344 ecore_hash_free_value_cb_set(hash, free); 371 ecore_hash_free_value_cb_set(hash, free);
345 372
346 for (i = 0; i < (unsigned int) request; ++i) 373 for (i = 0; i < (unsigned int)request; ++i)
347 { 374 {
348 elm = malloc(sizeof (Eina_Bench_Ecore) + 10); 375 elm = malloc(sizeof (Eina_Bench_Ecore) + 10);
349 if (!elm) continue; 376 if (!elm)
377 continue;
350 378
351 elm->key = (char*) (elm + 1); 379 elm->key = (char *)(elm + 1);
352 eina_convert_itoa(i, elm->key); 380 eina_convert_itoa(i, elm->key);
353 elm->value = i; 381 elm->value = i;
354 382
355 ecore_hash_set(hash, elm->key, elm); 383 ecore_hash_set(hash, elm->key, elm);
356 } 384 }
357 385
358 srand(time(NULL)); 386 srand(time(NULL));
359 387
360 for (j = 0; j < 200; ++j) 388 for (j = 0; j < 200; ++j)
361 for (i = 0; i < (unsigned int) request; ++i) 389 for (i = 0; i < (unsigned int)request; ++i)
362 { 390 {
363 char tmp_key[10]; 391 char tmp_key[10];
364 392
365 eina_convert_itoa(rand() % request, tmp_key); 393 eina_convert_itoa(rand() % request, tmp_key);
366 394
367 elm = ecore_hash_get(hash, tmp_key); 395 elm = ecore_hash_get(hash, tmp_key);
368 } 396 }
369 397
370 ecore_hash_destroy(hash); 398 ecore_hash_destroy(hash);
371} 399}
372 400
373void eina_bench_hash(Eina_Benchmark *bench) 401void eina_bench_hash(Eina_Benchmark *bench)
374{ 402{
375 eina_benchmark_register(bench, "superfast-lookup", EINA_BENCHMARK(eina_bench_lookup_superfast), 10, 3000, 10); 403 eina_benchmark_register(bench, "superfast-lookup",
376 eina_benchmark_register(bench, "djb2-lookup", EINA_BENCHMARK(eina_bench_lookup_djb2), 10, 3000, 10); 404 EINA_BENCHMARK(
377 eina_benchmark_register(bench, "djb2-lookup-inline", EINA_BENCHMARK(eina_bench_lookup_djb2_inline), 10, 3000, 10); 405 eina_bench_lookup_superfast), 10, 3000, 10);
378 eina_benchmark_register(bench, "rbtree", EINA_BENCHMARK(eina_bench_lookup_rbtree), 10, 3000, 10); 406 eina_benchmark_register(bench, "djb2-lookup",
407 EINA_BENCHMARK(
408 eina_bench_lookup_djb2), 10, 3000, 10);
409 eina_benchmark_register(bench, "djb2-lookup-inline",
410 EINA_BENCHMARK(
411 eina_bench_lookup_djb2_inline), 10, 3000, 10);
412 eina_benchmark_register(bench, "rbtree",
413 EINA_BENCHMARK(
414 eina_bench_lookup_rbtree), 10, 3000, 10);
379#ifdef EINA_BENCH_HAVE_GLIB 415#ifdef EINA_BENCH_HAVE_GLIB
380 eina_benchmark_register(bench, "ghash-lookup", EINA_BENCHMARK(eina_bench_lookup_ghash), 10, 3000, 10); 416 eina_benchmark_register(bench, "ghash-lookup",
417 EINA_BENCHMARK(
418 eina_bench_lookup_ghash), 10, 3000, 10);
381#endif 419#endif
382 eina_benchmark_register(bench, "evas-lookup", EINA_BENCHMARK(eina_bench_lookup_evas), 10, 3000, 10); 420 eina_benchmark_register(bench, "evas-lookup",
383 eina_benchmark_register(bench, "ecore-lookup", EINA_BENCHMARK(eina_bench_lookup_ecore), 10, 3000, 10); 421 EINA_BENCHMARK(
422 eina_bench_lookup_evas), 10, 3000, 10);
423 eina_benchmark_register(bench, "ecore-lookup",
424 EINA_BENCHMARK(
425 eina_bench_lookup_ecore), 10, 3000, 10);
384} 426}