summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-09-16 13:50:34 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-09-16 13:50:34 +0000
commit3f59016035e40944f4609cafde207cb4bf5ce27a (patch)
treeff093bdd24550f30ef06c8b1b8bd1bba3b91647e /legacy/eina/src/tests/eina_bench_hash.c
parentf5e373abd7a6c95c86014dae377f06c938b5867b (diff)
Add Ecore and Evas benchmark.
SVN revision: 36015
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index ce7df8942b..af2ea6032e 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -29,6 +29,14 @@
29#include <glib.h> 29#include <glib.h>
30#endif 30#endif
31 31
32#ifdef EINA_BENCH_HAVE_EVAS
33#include <Evas.h>
34#endif
35
36#ifdef EINA_BENCH_HAVE_ECORE
37#include <Ecore_Data.h>
38#endif
39
32#include "eina_hash.h" 40#include "eina_hash.h"
33#include "eina_array.h" 41#include "eina_array.h"
34#include "eina_bench.h" 42#include "eina_bench.h"
@@ -288,6 +296,101 @@ eina_bench_lookup_ghash(int request)
288} 296}
289#endif 297#endif
290 298
299#ifdef EINA_BENCH_HAVE_EVAS
300static void
301eina_bench_lookup_evas(int request)
302{
303 Evas_Hash *hash = NULL;
304 Eina_Array *array = NULL;
305 int *tmp_val;
306 Eina_Array_Iterator it;
307 unsigned int i;
308
309 array = eina_array_new(1000);
310
311 for (i = 0; i < (unsigned int) request; ++i)
312 {
313 char tmp_key[10];
314
315 tmp_val = malloc(sizeof (int));
316
317 if (!tmp_key || !tmp_val) continue ;
318
319 eina_convert_itoa(i, tmp_key);
320 *tmp_val = i;
321
322 hash = evas_hash_add(hash, tmp_key, tmp_val);
323
324 eina_array_push(array, tmp_val);
325 }
326
327 srand(time(NULL));
328
329 for (i = 0; i < (unsigned int) request; ++i)
330 {
331 char tmp_key[10];
332
333 eina_convert_itoa(rand() % request, tmp_key);
334
335 tmp_val = evas_hash_find(hash, tmp_key);
336 }
337
338 evas_hash_free(hash);
339
340 EINA_ARRAY_ITER_NEXT(array, i, tmp_val, it)
341 free(tmp_val);
342
343 eina_array_free(array);
344}
345#endif
346
347#ifdef EINA_BENCH_HAVE_ECORE
348typedef struct _Eina_Bench_Ecore Eina_Bench_Ecore;
349struct _Eina_Bench_Ecore
350{
351 char *key;
352 int value;
353};
354
355static void
356eina_bench_lookup_ecore(int request)
357{
358 Ecore_Hash *hash = NULL;
359 Eina_Bench_Ecore *elm;
360 unsigned int i;
361
362 hash = ecore_hash_new(ecore_str_hash, ecore_str_compare);
363
364 ecore_hash_free_key_cb_set(hash, NULL);
365 ecore_hash_free_value_cb_set(hash, free);
366
367 for (i = 0; i < (unsigned int) request; ++i)
368 {
369 elm = malloc(sizeof (Eina_Bench_Ecore) + 10);
370 if (!elm) continue;
371
372 elm->key = (char*) (elm + 1);
373 eina_convert_itoa(i, elm->key);
374 elm->value = i;
375
376 ecore_hash_set(hash, elm->key, elm);
377 }
378
379 srand(time(NULL));
380
381 for (i = 0; i < (unsigned int) request; ++i)
382 {
383 char tmp_key[10];
384
385 eina_convert_itoa(rand() % request, tmp_key);
386
387 elm = ecore_hash_get(hash, tmp_key);
388 }
389
390 ecore_hash_destroy(hash);
391}
392#endif
393
291void eina_bench_hash(Eina_Benchmark *bench) 394void eina_bench_hash(Eina_Benchmark *bench)
292{ 395{
293 eina_benchmark_register(bench, "superfast-lookup", EINA_BENCHMARK(eina_bench_lookup_superfast), 1000, 180000, 2500); 396 eina_benchmark_register(bench, "superfast-lookup", EINA_BENCHMARK(eina_bench_lookup_superfast), 1000, 180000, 2500);
@@ -297,4 +400,10 @@ void eina_bench_hash(Eina_Benchmark *bench)
297#ifdef EINA_BENCH_HAVE_GLIB 400#ifdef EINA_BENCH_HAVE_GLIB
298 eina_benchmark_register(bench, "ghash-lookup", EINA_BENCHMARK(eina_bench_lookup_ghash), 1000, 180000, 2500); 401 eina_benchmark_register(bench, "ghash-lookup", EINA_BENCHMARK(eina_bench_lookup_ghash), 1000, 180000, 2500);
299#endif 402#endif
403#ifdef EINA_BENCH_HAVE_EVAS
404 eina_benchmark_register(bench, "evas-lookup", EINA_BENCHMARK(eina_bench_lookup_evas), 1000, 180000, 2500);
405#endif
406#ifdef EINA_BENCH_HAVE_ECORE
407 eina_benchmark_register(bench, "ecore-lookup", EINA_BENCHMARK(eina_bench_lookup_ecore), 1000, 180000, 2500);
408#endif
300} 409}