summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-12-19 03:05:58 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-12-19 03:05:58 +0000
commit26158c95105b7aae41227fddb693dd99accee4fa (patch)
treedf1e908ad89797f537b73935515a1c669a3c4955 /legacy/eina/src/tests/eina_bench_hash.c
parentdac773751433a2e9ce16583fdf7ba0684ea4385b (diff)
remove eina tests
SVN revision: 55637
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c426
1 files changed, 0 insertions, 426 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
deleted file mode 100644
index c510c2bcf0..0000000000
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ /dev/null
@@ -1,426 +0,0 @@
1/* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library;
16 * if not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include <time.h>
27
28#ifdef EINA_BENCH_HAVE_GLIB
29# include <glib.h>
30#endif
31
32#include "Evas_Data.h"
33#include "Ecore_Data.h"
34
35#include "eina_hash.h"
36#include "eina_array.h"
37#include "eina_bench.h"
38#include "eina_rbtree.h"
39#include "eina_convert.h"
40
41typedef struct _Eina_Bench_Rbtree Eina_Bench_Rbtree;
42struct _Eina_Bench_Rbtree
43{
44 Eina_Rbtree node;
45 char key[10];
46 int value;
47};
48
49static Eina_Rbtree_Direction
50_eina_bench_rbtree_cmp(const Eina_Bench_Rbtree *left,
51 const Eina_Bench_Rbtree *right,
52 __UNUSED__ void *data)
53{
54 if (!left)
55 return EINA_RBTREE_RIGHT;
56
57 if (!right)
58 return EINA_RBTREE_LEFT;
59
60 return strcmp(left->key,
61 right->key) < 0 ? EINA_RBTREE_LEFT : EINA_RBTREE_RIGHT;
62}
63
64static inline int
65_eina_bench_rbtree_key(const Eina_Bench_Rbtree *node,
66 const char *key,
67 int length,
68 __UNUSED__ void *data)
69{
70 return strncmp(node->key, key, length);
71}
72
73static void
74_eina_bench_rbtree_free(Eina_Rbtree *node, __UNUSED__ void *data)
75{
76 free(node);
77}
78
79static void
80eina_bench_lookup_rbtree(int request)
81{
82 Eina_Rbtree *root = NULL;
83 int i;
84 int j;
85
86 for (i = 0; i < request; ++i)
87 {
88 Eina_Bench_Rbtree *tmp;
89
90 tmp = malloc(sizeof (Eina_Bench_Rbtree));
91 if (!tmp)
92 continue;
93
94 tmp->value = i;
95 eina_convert_itoa(i, tmp->key);
96
97 root = eina_rbtree_inline_insert(root,
98 &tmp->node,
99 EINA_RBTREE_CMP_NODE_CB(
100 _eina_bench_rbtree_cmp),
101 NULL);
102 }
103
104 srand(time(NULL));
105
106 for (j = 0; j < 200; ++j)
107 for (i = 0; i < request; ++i)
108 {
109 Eina_Rbtree *tmp;
110 char tmp_key[10];
111
112 eina_convert_itoa(rand() % request, tmp_key);
113
114 tmp = eina_rbtree_inline_lookup(root,
115 tmp_key,
116 10,
117 EINA_RBTREE_CMP_KEY_CB(
118 _eina_bench_rbtree_key),
119 NULL);
120 }
121
122 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL);
123}
124
125static void
126eina_bench_lookup_superfast(int request)
127{
128 Eina_Hash *hash = NULL;
129 int *tmp_val;
130 unsigned int i;
131 unsigned int j;
132
133 hash = eina_hash_string_superfast_new(free);
134
135 for (i = 0; i < (unsigned int)request; ++i)
136 {
137 char tmp_key[10];
138
139 tmp_val = malloc(sizeof (int));
140
141 if (!tmp_val)
142 continue;
143
144 eina_convert_itoa(i, tmp_key);
145 *tmp_val = i;
146
147 eina_hash_add(hash, tmp_key, tmp_val);
148 }
149
150 srand(time(NULL));
151
152 for (j = 0; j < 200; ++j)
153 for (i = 0; i < (unsigned int)request; ++i)
154 {
155 char tmp_key[10];
156
157 eina_convert_itoa(rand() % request, tmp_key);
158 tmp_val = eina_hash_find(hash, tmp_key);
159 }
160
161 eina_hash_free(hash);
162}
163
164static void
165eina_bench_lookup_djb2(int request)
166{
167 Eina_Hash *hash = NULL;
168 int *tmp_val;
169 unsigned int i;
170 unsigned int j;
171
172 hash = eina_hash_string_djb2_new(free);
173
174 for (i = 0; i < (unsigned int)request; ++i)
175 {
176 char tmp_key[10];
177
178 tmp_val = malloc(sizeof (int));
179
180 if (!tmp_val)
181 continue;
182
183 eina_convert_itoa(i, tmp_key);
184 *tmp_val = i;
185
186 eina_hash_add(hash, tmp_key, tmp_val);
187 }
188
189 srand(time(NULL));
190
191 for (j = 0; j < 200; ++j)
192 for (i = 0; i < (unsigned int)request; ++i)
193 {
194 char tmp_key[10];
195
196 eina_convert_itoa(rand() % request, tmp_key);
197
198 tmp_val = eina_hash_find(hash, tmp_key);
199 }
200
201 eina_hash_free(hash);
202}
203
204typedef struct _Eina_Bench_DJB2 Eina_Bench_DJB2;
205struct _Eina_Bench_DJB2
206{
207 char *key;
208 int value;
209};
210
211static void
212eina_bench_lookup_djb2_inline(int request)
213{
214 Eina_Hash *hash = NULL;
215 Eina_Bench_DJB2 *elm;
216 unsigned int i;
217 unsigned int j;
218
219 hash = eina_hash_string_djb2_new(free);
220
221 for (i = 0; i < (unsigned int)request; ++i)
222 {
223 int length;
224
225 elm = malloc(sizeof (Eina_Bench_DJB2) + 10);
226 if (!elm)
227 continue;
228
229 elm->key = (char *)(elm + 1);
230
231 length = eina_convert_itoa(i, elm->key) + 1;
232 elm->value = i;
233
234 eina_hash_direct_add_by_hash(hash, elm->key, length,
235 eina_hash_djb2(elm->key, length), elm);
236 }
237
238 srand(time(NULL));
239
240 for (j = 0; j < 200; ++j)
241 for (i = 0; i < (unsigned int)request; ++i)
242 {
243 char tmp_key[10];
244 int length = 6;
245
246 length = eina_convert_itoa(rand() % request, tmp_key) + 1;
247
248 elm =
249 eina_hash_find_by_hash(hash, tmp_key, length,
250 eina_hash_djb2(tmp_key, length));
251 }
252
253 eina_hash_free(hash);
254}
255
256#ifdef EINA_BENCH_HAVE_GLIB
257typedef struct _Eina_Bench_Glib Eina_Bench_Glib;
258struct _Eina_Bench_Glib
259{
260 char *key;
261 int value;
262};
263
264static void
265eina_bench_lookup_ghash(int request)
266{
267 Eina_Bench_Glib *elm;
268 GHashTable *hash;
269 unsigned int i;
270 unsigned int j;
271
272 hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
273
274 for (i = 0; i < (unsigned int)request; ++i)
275 {
276 elm = malloc(sizeof (Eina_Bench_Glib) + 10);
277 if (!elm)
278 continue;
279
280 elm->key = (char *)(elm + 1);
281
282 eina_convert_itoa(i, elm->key);
283 elm->value = i;
284
285 g_hash_table_insert(hash, elm->key, elm);
286 }
287
288 srand(time(NULL));
289
290 for (j = 0; j < 200; ++j)
291 for (i = 0; i < (unsigned int)request; ++i)
292 {
293 char tmp_key[10];
294
295 eina_convert_itoa(rand() % request, tmp_key);
296
297 elm = g_hash_table_lookup(hash, tmp_key);
298 }
299
300 g_hash_table_destroy(hash);
301}
302#endif
303
304static void
305eina_bench_lookup_evas(int request)
306{
307 Evas_Hash *hash = NULL;
308 Eina_Array *array = NULL;
309 int *tmp_val;
310 Eina_Array_Iterator it;
311 unsigned int i;
312 unsigned int j;
313
314 array = eina_array_new(1000);
315
316 for (i = 0; i < (unsigned int)request; ++i)
317 {
318 char tmp_key[10];
319
320 tmp_val = malloc(sizeof (int));
321
322 if (!tmp_val)
323 continue;
324
325 eina_convert_itoa(i, tmp_key);
326 *tmp_val = i;
327
328 hash = evas_hash_add(hash, tmp_key, tmp_val);
329
330 eina_array_push(array, tmp_val);
331 }
332
333 srand(time(NULL));
334
335 for (j = 0; j < 200; ++j)
336 for (i = 0; i < (unsigned int)request; ++i)
337 {
338 char tmp_key[10];
339
340 eina_convert_itoa(rand() % request, tmp_key);
341
342 tmp_val = evas_hash_find(hash, tmp_key);
343 }
344
345 evas_hash_free(hash);
346
347 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
348 free(tmp_val);
349
350 eina_array_free(array);
351}
352
353typedef struct _Eina_Bench_Ecore Eina_Bench_Ecore;
354struct _Eina_Bench_Ecore
355{
356 char *key;
357 int value;
358};
359
360static void
361eina_bench_lookup_ecore(int request)
362{
363 Ecore_Hash *hash = NULL;
364 Eina_Bench_Ecore *elm;
365 unsigned int i;
366 unsigned int j;
367
368 hash = ecore_hash_new(ecore_str_hash, ecore_str_compare);
369
370 ecore_hash_free_key_cb_set(hash, NULL);
371 ecore_hash_free_value_cb_set(hash, free);
372
373 for (i = 0; i < (unsigned int)request; ++i)
374 {
375 elm = malloc(sizeof (Eina_Bench_Ecore) + 10);
376 if (!elm)
377 continue;
378
379 elm->key = (char *)(elm + 1);
380 eina_convert_itoa(i, elm->key);
381 elm->value = i;
382
383 ecore_hash_set(hash, elm->key, elm);
384 }
385
386 srand(time(NULL));
387
388 for (j = 0; j < 200; ++j)
389 for (i = 0; i < (unsigned int)request; ++i)
390 {
391 char tmp_key[10];
392
393 eina_convert_itoa(rand() % request, tmp_key);
394
395 elm = ecore_hash_get(hash, tmp_key);
396 }
397
398 ecore_hash_destroy(hash);
399}
400
401void eina_bench_hash(Eina_Benchmark *bench)
402{
403 eina_benchmark_register(bench, "superfast-lookup",
404 EINA_BENCHMARK(
405 eina_bench_lookup_superfast), 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);
415#ifdef EINA_BENCH_HAVE_GLIB
416 eina_benchmark_register(bench, "ghash-lookup",
417 EINA_BENCHMARK(
418 eina_bench_lookup_ghash), 10, 3000, 10);
419#endif
420 eina_benchmark_register(bench, "evas-lookup",
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);
426}