summaryrefslogtreecommitdiff
path: root/src/benchmarks/eina/eina_bench_promise.c
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-24 17:36:26 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-26 14:20:24 -0300
commitedd99d24ef797a9b574e2ff0b5821be6e45bc00c (patch)
treecaec2c5364cccf4030d1567151c0870730fa27b2 /src/benchmarks/eina/eina_bench_promise.c
parent2c043ca2057af6338ad8ff43c044d3b0f602898c (diff)
eina: Add benchmarks for eina promises
Diffstat (limited to '')
-rw-r--r--src/benchmarks/eina/eina_bench_promise.c359
1 files changed, 359 insertions, 0 deletions
diff --git a/src/benchmarks/eina/eina_bench_promise.c b/src/benchmarks/eina/eina_bench_promise.c
new file mode 100644
index 0000000000..a6ba2bb222
--- /dev/null
+++ b/src/benchmarks/eina/eina_bench_promise.c
@@ -0,0 +1,359 @@
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 <time.h>
26
27#include "Evas_Data.h"
28#include "Ecore_Data.h"
29
30#include "eina_stringshare.h"
31#include "eina_bench.h"
32#include "eina_convert.h"
33#include "eina_main.h"
34
35#include <Eina.h>
36
37struct value_type
38{
39 int x;
40 int y;
41 int w;
42 int h;
43};
44
45void cb(void* data EINA_UNUSED, void* value)
46{
47 struct value_type* p = value;
48 volatile int v = p->x * p->y * p->w * p->h;
49 (void)v;
50}
51
52void pointer_cb(void* data EINA_UNUSED, void* value)
53{
54 struct value_type* p = *(struct value_type**)value;
55 volatile int v = p->x * p->y * p->w * p->h;
56 (void)v;
57}
58
59static void
60eina_bench_promise_sync_then(int request)
61{
62 const char *tmp;
63 unsigned int j;
64 int i;
65
66 eina_init();
67
68 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
69 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
70 eina_promise_ref(promise);
71
72 struct value_type v = { 0, 0, 0, 0 };
73 eina_promise_owner_value_set(owner, &v, NULL);
74
75 for (j = 0; j != 200; ++j)
76 for (i = 0; i != request; ++i)
77 {
78 eina_promise_then(promise, &cb, NULL, NULL);
79 }
80
81 /* Suppress warnings as we really don't want to do anything. */
82 (void) tmp;
83
84 eina_promise_unref(promise);
85 eina_shutdown();
86}
87
88static void
89eina_bench_promise_copy_value_set_after_then(int request)
90{
91 const char *tmp;
92 unsigned int j;
93 int i;
94
95 eina_init();
96
97 struct value_type const v = {0, 0, 0, 0};
98
99 for (j = 0; j != 200; ++j)
100 for (i = 0; i != request; ++i)
101 {
102 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
103 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
104
105 eina_promise_then(promise, &cb, NULL, NULL);
106 eina_promise_owner_value_set(owner, &v, NULL);
107 }
108
109 /* Suppress warnings as we really don't want to do anything. */
110 (void) tmp;
111
112 eina_shutdown();
113}
114
115static void
116eina_bench_promise_no_copy_value_set_after_then(int request)
117{
118 const char *tmp;
119 unsigned int j;
120 int i;
121
122 eina_init();
123
124 for (j = 0; j != 200; ++j)
125 for (i = 0; i != request; ++i)
126 {
127 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
128 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
129 struct value_type* v = eina_promise_owner_buffer_get(owner);
130
131 eina_promise_then(promise, &cb, NULL, NULL);
132
133 v->x = v->y = v-> w = v->h = 0;
134 eina_promise_owner_value_set(owner, NULL, NULL);
135 }
136
137 /* Suppress warnings as we really don't want to do anything. */
138 (void) tmp;
139
140 eina_shutdown();
141}
142
143static void
144eina_bench_promise_no_copy_value_set_before_then(int request)
145{
146 const char *tmp;
147 unsigned int j;
148 int i;
149
150 eina_init();
151
152 for (j = 0; j != 200; ++j)
153 for (i = 0; i != request; ++i)
154 {
155 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
156 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
157 struct value_type* v = eina_promise_owner_buffer_get(owner);
158
159 v->x = v->y = v-> w = v->h = 0;
160 eina_promise_owner_value_set(owner, NULL, NULL);
161
162 eina_promise_then(promise, &cb, NULL, NULL);
163 }
164
165 /* Suppress warnings as we really don't want to do anything. */
166 (void) tmp;
167
168 eina_shutdown();
169}
170
171static void
172eina_bench_promise_copy_value_set_before_then(int request)
173{
174 const char *tmp;
175 unsigned int j;
176 int i;
177
178 eina_init();
179
180 struct value_type const v = {0, 0, 0, 0};
181
182 for (j = 0; j != 200; ++j)
183 for (i = 0; i != request; ++i)
184 {
185 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type));
186 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
187
188 eina_promise_then(promise, &cb, NULL, NULL);
189 eina_promise_owner_value_set(owner, &v, NULL);
190 }
191
192 /* Suppress warnings as we really don't want to do anything. */
193 (void) tmp;
194
195 eina_shutdown();
196}
197
198static void indirect_free(void* p)
199{
200 free(*(void**)p);
201}
202
203static void
204eina_bench_promise_pointer_value_set_before_then(int request)
205{
206 const char *tmp;
207 unsigned int j;
208 int i;
209
210 eina_init();
211
212 for (j = 0; j != 200; ++j)
213 for (i = 0; i != request; ++i)
214 {
215 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
216 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
217
218 struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
219 = malloc(sizeof(struct value_type));
220 p->x = p->y = p->w = p->h = 0;
221
222 eina_promise_then(promise, &pointer_cb, NULL, NULL);
223 eina_promise_owner_value_set(owner, NULL, &indirect_free);
224 }
225
226 /* Suppress warnings as we really don't want to do anything. */
227 (void) tmp;
228
229 eina_shutdown();
230}
231
232static void
233eina_bench_promise_pointer_value_set_after_then(int request)
234{
235 const char *tmp;
236 unsigned int j;
237 int i;
238
239 eina_init();
240
241 for (j = 0; j != 200; ++j)
242 for (i = 0; i != request; ++i)
243 {
244 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
245 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
246
247 struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
248 = malloc(sizeof(struct value_type));
249 p->x = p->y = p->w = p->h = 0;
250
251 eina_promise_owner_value_set(owner, NULL, &indirect_free);
252 eina_promise_then(promise, &pointer_cb, NULL, NULL);
253 }
254
255 /* Suppress warnings as we really don't want to do anything. */
256 (void) tmp;
257
258 eina_shutdown();
259}
260
261static Eina_Mempool* mempool;
262
263static void indirect_mempool_free(void* p)
264{
265 eina_mempool_free(mempool, *(void**)p);
266}
267
268static void
269eina_bench_promise_pointer_value_set_before_then_pooled(int request)
270{
271 const char *tmp;
272 unsigned int j;
273 int i;
274
275 eina_init();
276
277
278
279 for (j = 0; j != 200; ++j)
280 for (i = 0; i != request; ++i)
281 {
282 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
283 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
284
285 struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
286 = eina_mempool_malloc(mempool, sizeof(struct value_type));
287 p->x = p->y = p->w = p->h = 0;
288
289 eina_promise_then(promise, &pointer_cb, NULL, NULL);
290 eina_promise_owner_value_set(owner, NULL, &indirect_mempool_free);
291 }
292
293 /* Suppress warnings as we really don't want to do anything. */
294 (void) tmp;
295
296 eina_mempool_del(mempool);
297
298 eina_shutdown();
299}
300
301static void
302eina_bench_promise_pointer_value_set_after_then_pooled(int request)
303{
304 const char *tmp;
305 unsigned int j;
306 int i;
307
308 eina_init();
309
310 for (j = 0; j != 200; ++j)
311 for (i = 0; i != request; ++i)
312 {
313 Eina_Promise_Owner* owner = eina_promise_default_add(sizeof(struct value_type*));
314 Eina_Promise* promise = eina_promise_owner_promise_get(owner);
315
316 struct value_type* p = *(struct value_type**)eina_promise_owner_buffer_get(owner)
317 = eina_mempool_malloc(mempool, sizeof(struct value_type));
318 p->x = p->y = p->w = p->h = 0;
319
320 eina_promise_owner_value_set(owner, NULL, &indirect_mempool_free);
321 eina_promise_then(promise, &pointer_cb, NULL, NULL);
322 }
323
324 /* Suppress warnings as we really don't want to do anything. */
325 (void) tmp;
326
327 eina_shutdown();
328}
329
330void eina_bench_promise(Eina_Benchmark *bench)
331{
332 eina_benchmark_register(bench, "promise synchronous then",
333 EINA_BENCHMARK(
334 eina_bench_promise_sync_then), 100, 20100, 500);
335 eina_benchmark_register(bench, "promise copy value set after then",
336 EINA_BENCHMARK(
337 eina_bench_promise_copy_value_set_after_then), 100, 20100, 500);
338 eina_benchmark_register(bench, "promise copy value set before then",
339 EINA_BENCHMARK(
340 eina_bench_promise_copy_value_set_before_then), 100, 20100, 500);
341 eina_benchmark_register(bench, "promise no copy value set after then",
342 EINA_BENCHMARK(
343 eina_bench_promise_no_copy_value_set_after_then), 100, 20100, 500);
344 eina_benchmark_register(bench, "promise no copy value set before then",
345 EINA_BENCHMARK(
346 eina_bench_promise_no_copy_value_set_before_then), 100, 20100, 500);
347 eina_benchmark_register(bench, "promise pointer value set after then",
348 EINA_BENCHMARK(
349 eina_bench_promise_pointer_value_set_after_then), 100, 20100, 500);
350 eina_benchmark_register(bench, "promise pointer value set before then",
351 EINA_BENCHMARK(
352 eina_bench_promise_pointer_value_set_before_then), 100, 20100, 500);
353 eina_benchmark_register(bench, "promise pointer value set after then mempool",
354 EINA_BENCHMARK(
355 eina_bench_promise_pointer_value_set_after_then), 100, 20100, 500);
356 eina_benchmark_register(bench, "promise pointer value set before then mempool",
357 EINA_BENCHMARK(
358 eina_bench_promise_pointer_value_set_before_then), 100, 20100, 500);
359}