EFL 1.7 svn doobies
[profile/ivi/eina.git] / src / tests / eina_bench_mempool.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 #ifdef EINA_BENCH_HAVE_GLIB
24 # include <glib.h>
25 #endif
26
27 #include "eina_bench.h"
28 #include "Eina.h"
29
30 static void
31 _eina_mempool_bench(Eina_Mempool *mp, int request)
32 {
33    Eina_Array *array;
34    int i;
35    int j;
36
37    eina_init();
38    array = eina_array_new(32);
39
40    for (i = 0; i < 100; ++i)
41      {
42         for (j = 0; j < request; ++j)
43           {
44              eina_array_push(array, eina_mempool_malloc(mp, sizeof (int)));
45           }
46
47         for (j = 0; j < request; ++j)
48           {
49              eina_mempool_free(mp, eina_array_pop(array));
50           }
51      }
52
53    eina_array_free(array);
54    eina_shutdown();
55 }
56
57 #ifdef EINA_BUILD_CHAINED_POOL
58 static void
59 eina_mempool_chained_mempool(int request)
60 {
61    Eina_Mempool *mp;
62
63    mp = eina_mempool_add("chained_mempool", "test", NULL, sizeof (int), 256);
64    _eina_mempool_bench(mp, request);
65    eina_mempool_del(mp);
66 }
67 #endif
68
69 #ifdef EINA_BUILD_PASS_THROUGH
70 static void
71 eina_mempool_pass_through(int request)
72 {
73    Eina_Mempool *mp;
74
75    mp = eina_mempool_add("pass_through", "test", NULL, sizeof (int), 8, 0);
76    _eina_mempool_bench(mp, request);
77    eina_mempool_del(mp);
78 }
79 #endif
80
81 #ifdef EINA_BUILD_FIXED_BITMAP
82 static void
83 eina_mempool_fixed_bitmap(int request)
84 {
85    Eina_Mempool *mp;
86
87    mp = eina_mempool_add("fixed_bitmap", "test", NULL, sizeof (int));
88    _eina_mempool_bench(mp, request);
89    eina_mempool_del(mp);
90 }
91 #endif
92
93 #ifdef EINA_BUILD_EMEMOA_FIXED
94 static void
95 eina_mempool_ememoa_fixed(int request)
96 {
97    Eina_Mempool *mp;
98
99    mp = eina_mempool_add("ememoa_fixed", "test", NULL, sizeof (int), 8, 0);
100    _eina_mempool_bench(mp, request);
101    eina_mempool_del(mp);
102 }
103 #endif
104
105 #ifdef EINA_BUILD_EMEMOA_UNKNOWN
106 static void
107 eina_mempool_ememoa_unknown(int request)
108 {
109    Eina_Mempool *mp;
110
111    mp = eina_mempool_add("ememoa_unknown",
112                          "test",
113                          NULL,
114                          0,
115                          2,
116                          sizeof (int),
117                          8,
118                          sizeof (int) * 2,
119                          8);
120    _eina_mempool_bench(mp, request);
121    eina_mempool_del(mp);
122 }
123 #endif
124
125 #ifdef EINA_BENCH_HAVE_GLIB
126 static void
127 eina_mempool_glib(int request)
128 {
129    Eina_Array *array;
130    int i;
131    int j;
132
133    eina_init();
134    array = eina_array_new(32);
135
136    for (i = 0; i < 100; ++i)
137      {
138         for (j = 0; j < request; ++j)
139           {
140              eina_array_push(array, g_slice_alloc(sizeof (int)));
141           }
142
143         for (j = 0; j < request; ++j)
144           {
145              g_slice_free1(sizeof (int), eina_array_pop(array));
146           }
147      }
148
149    eina_array_free(array);
150    eina_shutdown();
151
152 }
153 #endif
154
155 void
156 eina_bench_mempool(Eina_Benchmark *bench)
157 {
158 #ifdef EINA_BUILD_CHAINED_POOL
159    eina_benchmark_register(bench, "chained mempool",
160                            EINA_BENCHMARK(
161                               eina_mempool_chained_mempool), 10, 10000, 10);
162 #endif
163 #ifdef EINA_BUILD_PASS_THROUGH
164    eina_benchmark_register(bench, "pass through",
165                            EINA_BENCHMARK(
166                               eina_mempool_pass_through),    10, 10000, 10);
167 #endif
168 #ifdef EINA_BUILD_FIXED_BITMAP
169    eina_benchmark_register(bench, "fixed bitmap",
170                            EINA_BENCHMARK(
171                               eina_mempool_fixed_bitmap),    10, 10000, 10);
172 #endif
173 #ifdef EINA_BUILD_EMEMOA_FIXED
174    eina_benchmark_register(bench, "ememoa fixed",
175                            EINA_BENCHMARK(
176                               eina_mempool_ememoa_fixed),    10, 10000, 10);
177 #endif
178 #ifdef EINA_BUILD_EMEMOA_UNKNOWN
179    eina_benchmark_register(bench, "ememoa unknown",
180                            EINA_BENCHMARK(
181                               eina_mempool_ememoa_unknown),  10, 10000, 10);
182 #endif
183 #ifdef EINA_BENCH_HAVE_GLIB
184    eina_benchmark_register(bench, "gslice",
185                            EINA_BENCHMARK(
186                               eina_mempool_glib),            10, 10000, 10);
187 #endif
188 }