EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / tests / eina_bench.c
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 <limits.h>
26
27 #include "eina_bench.h"
28 #include "Eina.h"
29
30 typedef struct _Eina_Benchmark_Case Eina_Benchmark_Case;
31 struct _Eina_Benchmark_Case
32 {
33    const char *bench_case;
34    void (*build)(Eina_Benchmark *bench);
35 };
36
37 static const Eina_Benchmark_Case etc[] = {
38    { "Hash", eina_bench_hash },
39    /* { "Array vs List vs Inlist", eina_bench_array }, */
40    /* { "Stringshare", eina_bench_stringshare }, */
41    /* { "Convert", eina_bench_convert }, */
42    /* { "Sort", eina_bench_sort }, */
43    /* { "Mempool", eina_bench_mempool }, */
44    /* { "Rectangle_Pool", eina_bench_rectangle_pool }, */
45    // { "Render Loop", eina_bench_quadtree },
46    { NULL, NULL }
47 };
48
49 /* FIXME this is a copy from eina_test_mempool
50  * we should remove the duplication
51  */
52 static Eina_Array *_modules;
53 static void _mempool_init(void)
54 {
55    eina_init();
56    /* force modules to be loaded in case they are not installed */
57    _modules = eina_module_list_get(NULL,
58                                    PACKAGE_BUILD_DIR "/src/modules",
59                                    EINA_TRUE,
60                                    NULL,
61                                    NULL);
62    eina_module_list_load(_modules);
63 }
64
65 static void _mempool_shutdown(void)
66 {
67    eina_module_list_free(_modules);
68    /* TODO delete the list */
69    eina_shutdown();
70 }
71
72 int
73 main(int argc, char **argv)
74 {
75    Eina_Benchmark *test;
76    unsigned int i;
77
78    if (argc != 2)
79       return -1;
80
81    _mempool_init();
82
83    eina_init();
84
85    for (i = 0; etc[i].bench_case; ++i)
86      {
87         test = eina_benchmark_new(etc[i].bench_case, argv[1]);
88         if (!test)
89            continue;
90
91         etc[i].build(test);
92
93         eina_benchmark_run(test);
94
95         eina_benchmark_free(test);
96      }
97
98    eina_bench_e17();
99
100    eina_shutdown();
101
102    _mempool_shutdown();
103    return 0;
104 }