aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_bench_array.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/tests/eina_bench_array.c')
-rw-r--r--libraries/eina/src/tests/eina_bench_array.c699
1 files changed, 699 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_bench_array.c b/libraries/eina/src/tests/eina_bench_array.c
new file mode 100644
index 0000000..425eddd
--- /dev/null
+++ b/libraries/eina/src/tests/eina_bench_array.c
@@ -0,0 +1,699 @@
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#ifdef EINA_BENCH_HAVE_GLIB
28# include <glib.h>
29#endif
30
31#include "Evas_Data.h"
32#include "Ecore_Data.h"
33
34#include "eina_bench.h"
35#include "eina_array.h"
36#include "eina_list.h"
37#include "eina_inlist.h"
38#include "eina_main.h"
39
40typedef struct _Eina_Bench_Object Eina_Bench_Object;
41struct _Eina_Bench_Object
42{
43 EINA_INLIST;
44
45 void *somewhere;
46 int data;
47 Eina_Bool keep;
48};
49
50static Eina_Bool keep(void *data, __UNUSED__ void *gdata)
51{
52 Eina_Bench_Object *bo = data;
53
54 if (bo->keep == EINA_TRUE)
55 return EINA_TRUE;
56
57 free(bo);
58 return EINA_FALSE;
59}
60
61static void
62eina_bench_array_4evas_render_inline(int request)
63{
64 Eina_Array *array;
65 Eina_Bench_Object *ebo;
66 Eina_Array_Iterator it;
67 unsigned int i;
68 unsigned int j;
69
70 srand(time(NULL));
71
72 eina_init();
73
74 array = eina_array_new(64);
75
76 for (i = 0; i < 1000; ++i)
77 {
78 for (j = 0; j < (unsigned int)request; ++j)
79 {
80 ebo = malloc(sizeof (Eina_Bench_Object));
81 if (!ebo)
82 continue;
83
84 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
85
86 eina_array_push(array, ebo);
87 }
88
89 if (i == 500)
90 {
91 EINA_ARRAY_ITER_NEXT(array, j, ebo, it)
92 free(ebo);
93
94 eina_array_clean(array);
95 }
96 else if (i % 30 == 0)
97 eina_array_remove(array, keep, NULL);
98
99 EINA_ARRAY_ITER_NEXT(array, j, ebo, it)
100 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
101 }
102
103 EINA_ARRAY_ITER_NEXT(array, j, ebo, it)
104 free(ebo);
105
106 eina_array_free(array);
107
108 eina_shutdown();
109}
110
111static Eina_Bool
112eina_iterator_ebo_free(__UNUSED__ const Eina_Array *array,
113 Eina_Bench_Object *ebo, __UNUSED__ void *fdata)
114{
115 free(ebo);
116 return EINA_TRUE;
117}
118
119static Eina_Bool
120eina_iterator_ebo_rand(__UNUSED__ const void *container,
121 Eina_Bench_Object *ebo, __UNUSED__ void *fdata)
122{
123 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
124 return EINA_TRUE;
125}
126
127static void
128eina_bench_array_4evas_render_iterator(int request)
129{
130 Eina_Array *array;
131 Eina_Bench_Object *ebo;
132 Eina_Iterator *it;
133 unsigned int i;
134 unsigned int j;
135
136 srand(time(NULL));
137
138 eina_init();
139
140 array = eina_array_new(64);
141
142 for (i = 0; i < 1000; ++i)
143 {
144 for (j = 0; j < (unsigned int)request; ++j)
145 {
146 ebo = malloc(sizeof (Eina_Bench_Object));
147 if (!ebo)
148 continue;
149
150 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
151
152 eina_array_push(array, ebo);
153 }
154
155 if (i == 500)
156 {
157 it = eina_array_iterator_new(array);
158 eina_iterator_foreach(it, EINA_EACH_CB(eina_iterator_ebo_free), NULL);
159 eina_iterator_free(it);
160
161 eina_array_clean(array);
162 }
163 else if (i % 30 == 0)
164 eina_array_remove(array, keep, NULL);
165
166 it = eina_array_iterator_new(array);
167 eina_iterator_foreach(it, EINA_EACH_CB(eina_iterator_ebo_rand), NULL);
168 eina_iterator_free(it);
169 }
170
171 it = eina_array_iterator_new(array);
172 eina_iterator_foreach(it, EINA_EACH_CB(eina_iterator_ebo_free), NULL);
173 eina_iterator_free(it);
174
175 eina_array_free(array);
176
177 eina_shutdown();
178}
179
180static void
181eina_bench_list_4evas_render(int request)
182{
183 Eina_List *list = NULL;
184 Eina_List *tmp;
185 Eina_Bench_Object *ebo;
186 int i;
187 int j;
188
189 eina_init();
190
191 for (i = 0; i < 1000; ++i)
192 {
193 for (j = 0; j < request; ++j)
194 {
195 ebo = malloc(sizeof (Eina_Bench_Object));
196 if (!ebo)
197 continue;
198
199 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
200
201 list = eina_list_prepend(list, ebo);
202 }
203
204 if (i == 500)
205 while (list)
206 {
207 free(eina_list_data_get(list));
208 list = eina_list_remove_list(list, list);
209 }
210 else if (i % 30 == 0)
211 {
212 tmp = list;
213 while (tmp)
214 {
215 Eina_List *reminder = tmp;
216
217 ebo = eina_list_data_get(reminder);
218 tmp = eina_list_next(tmp);
219
220 if (ebo->keep == EINA_FALSE)
221 {
222 list = eina_list_remove_list(list, reminder);
223 free(ebo);
224 }
225 }
226 }
227
228 for (tmp = list; tmp; tmp = eina_list_next(tmp))
229 {
230 ebo = eina_list_data_get(tmp);
231
232 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
233 }
234 }
235
236 while (list)
237 {
238 free(eina_list_data_get(list));
239 list = eina_list_remove_list(list, list);
240 }
241
242 eina_shutdown();
243}
244
245static void
246eina_bench_list_4evas_render_iterator(int request)
247{
248 Eina_List *list = NULL;
249 Eina_List *tmp;
250 Eina_Bench_Object *ebo;
251 Eina_Iterator *it;
252 int i;
253 int j;
254
255 eina_init();
256
257 for (i = 0; i < 1000; ++i)
258 {
259 for (j = 0; j < request; ++j)
260 {
261 ebo = malloc(sizeof (Eina_Bench_Object));
262 if (!ebo)
263 continue;
264
265 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
266
267 list = eina_list_prepend(list, ebo);
268 }
269
270 if (i == 500)
271 while (list)
272 {
273 free(eina_list_data_get(list));
274 list = eina_list_remove_list(list, list);
275 }
276 else if (i % 30 == 0)
277 {
278 tmp = list;
279 while (tmp)
280 {
281 Eina_List *reminder = tmp;
282
283 ebo = eina_list_data_get(reminder);
284 tmp = eina_list_next(tmp);
285
286 if (ebo->keep == EINA_FALSE)
287 {
288 list = eina_list_remove_list(list, reminder);
289 free(ebo);
290 }
291 }
292 }
293
294 it = eina_list_iterator_new(list);
295 eina_iterator_foreach(it, EINA_EACH_CB(eina_iterator_ebo_rand), NULL);
296 eina_iterator_free(it);
297 }
298
299 while (list)
300 {
301 free(eina_list_data_get(list));
302 list = eina_list_remove_list(list, list);
303 }
304
305 eina_shutdown();
306}
307
308static void
309eina_bench_inlist_4evas_render(int request)
310{
311 Eina_Inlist *head = NULL;
312 Eina_Inlist *tmp;
313 Eina_Bench_Object *ebo;
314 int i;
315 int j;
316
317 for (i = 0; i < 1000; ++i)
318 {
319 for (j = 0; j < request; ++j)
320 {
321 ebo = malloc(sizeof (Eina_Bench_Object));
322 if (!ebo)
323 continue;
324
325 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
326
327 head = eina_inlist_prepend(head, EINA_INLIST_GET(ebo));
328 }
329
330 if (i == 500)
331 while (head)
332 {
333 tmp = head;
334 head = head->next;
335 free(tmp);
336 }
337 else if (i % 30 == 0)
338 {
339 tmp = head;
340 while(tmp)
341 {
342 ebo = (Eina_Bench_Object *)tmp;
343
344 tmp = tmp->next;
345 if (ebo->keep == EINA_FALSE)
346 {
347 head = eina_inlist_remove(head, EINA_INLIST_GET(ebo));
348 free(ebo);
349 }
350 }
351 }
352
353 EINA_INLIST_FOREACH(head, ebo)
354 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
355 }
356
357 while (head)
358 {
359 tmp = head;
360 head = head->next;
361 free(tmp);
362 }
363}
364
365static void
366eina_bench_inlist_4evas_render_iterator(int request)
367{
368 Eina_Inlist *head = NULL;
369 Eina_Inlist *tmp;
370 Eina_Bench_Object *ebo;
371 Eina_Iterator *it;
372 int i;
373 int j;
374
375 for (i = 0; i < 1000; ++i)
376 {
377 for (j = 0; j < request; ++j)
378 {
379 ebo = malloc(sizeof (Eina_Bench_Object));
380 if (!ebo)
381 continue;
382
383 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
384
385 head = eina_inlist_prepend(head, EINA_INLIST_GET(ebo));
386 }
387
388 if (i == 500)
389 while (head)
390 {
391 tmp = head;
392 head = head->next;
393 free(tmp);
394 }
395 else if (i % 30 == 0)
396 {
397 tmp = head;
398 while(tmp)
399 {
400 ebo = (Eina_Bench_Object *)tmp;
401
402 tmp = tmp->next;
403 if (ebo->keep == EINA_FALSE)
404 {
405 head = eina_inlist_remove(head, EINA_INLIST_GET(ebo));
406 free(ebo);
407 }
408 }
409 }
410
411 it = eina_inlist_iterator_new(head);
412 eina_iterator_foreach(it, EINA_EACH_CB(eina_iterator_ebo_rand), NULL);
413 eina_iterator_free(it);
414 }
415
416 while (head)
417 {
418 tmp = head;
419 head = head->next;
420 free(tmp);
421 }
422}
423
424#ifdef EINA_BENCH_HAVE_GLIB
425static void
426eina_bench_glist_4evas_render(int request)
427{
428 GList *list = NULL;
429 GList *tmp;
430 Eina_Bench_Object *ebo;
431 int i;
432 int j;
433
434 for (i = 0; i < 1000; ++i)
435 {
436 for (j = 0; j < request; ++j)
437 {
438 ebo = malloc(sizeof (Eina_Bench_Object));
439 if (!ebo)
440 continue;
441
442 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
443
444 list = g_list_prepend(list, ebo);
445 }
446
447 if (i == 500)
448 while (list)
449 {
450 free(list->data);
451 list = g_list_delete_link(list, list);
452 }
453 else if (i % 30 == 0)
454 {
455 tmp = list;
456 while (tmp)
457 {
458 GList *reminder = tmp;
459
460 ebo = reminder->data;
461 tmp = g_list_next(tmp);
462
463 if (ebo->keep == EINA_FALSE)
464 {
465 list = g_list_delete_link(list, reminder);
466 free(ebo);
467 }
468 }
469 }
470
471 for (tmp = list; tmp; tmp = g_list_next(tmp))
472 {
473 ebo = tmp->data;
474
475 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
476 }
477 }
478
479 while (list)
480 {
481 free(list->data);
482 list = g_list_delete_link(list, list);
483 }
484}
485
486static void
487eina_bench_gptrarray_4evas_render(int request)
488{
489 GPtrArray *array = NULL;
490 Eina_Bench_Object *ebo;
491 unsigned int j;
492 int i;
493
494 array = g_ptr_array_new();
495
496 for (i = 0; i < 1000; ++i)
497 {
498 for (j = 0; j < (unsigned int)request; ++j)
499 {
500 ebo = malloc(sizeof (Eina_Bench_Object));
501 if (!ebo)
502 continue;
503
504 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
505
506 g_ptr_array_add(array, ebo);
507 }
508
509 if (i == 500)
510 {
511 for (j = 0; j < array->len; ++j)
512 free(g_ptr_array_index(array, j));
513 g_ptr_array_remove_range(array, 0, array->len);
514 }
515 else if (i % 30 == 0)
516 for (j = 0; j < array->len; )
517 {
518 ebo = g_ptr_array_index(array, j);
519
520 if (ebo->keep == EINA_FALSE)
521 free(g_ptr_array_remove_index_fast(array, j));
522 else
523 j++;
524 }
525
526 for (j = 0; j < array->len; ++j)
527 {
528 ebo = g_ptr_array_index(array, j);
529
530 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
531 }
532 }
533
534 for (j = 0; j < array->len; ++j)
535 free(g_ptr_array_index(array, j));
536 g_ptr_array_free(array, TRUE);
537}
538#endif
539
540static void
541eina_bench_evas_list_4evas_render(int request)
542{
543 Evas_List *list = NULL;
544 Evas_List *tmp;
545 Eina_Bench_Object *ebo;
546 int i;
547 int j;
548
549 for (i = 0; i < 1000; ++i)
550 {
551 for (j = 0; j < request; ++j)
552 {
553 ebo = malloc(sizeof (Eina_Bench_Object));
554 if (!ebo)
555 continue;
556
557 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
558
559 list = evas_list_prepend(list, ebo);
560 }
561
562 if (i == 500)
563 while (list)
564 {
565 free(evas_list_data(list));
566 list = evas_list_remove_list(list, list);
567 }
568 else if (i % 30 == 0)
569 {
570 tmp = list;
571 while (tmp)
572 {
573 Evas_List *reminder = tmp;
574
575 ebo = evas_list_data(reminder);
576 tmp = evas_list_next(tmp);
577
578 if (ebo->keep == EINA_FALSE)
579 {
580 list = evas_list_remove_list(list, reminder);
581 free(ebo);
582 }
583 }
584 }
585
586 for (tmp = list; tmp; tmp = evas_list_next(tmp))
587 {
588 ebo = evas_list_data(tmp);
589
590 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
591 }
592 }
593
594 while (list)
595 {
596 free(evas_list_data(list));
597 list = evas_list_remove_list(list, list);
598 }
599}
600
601static void
602_eina_ecore_for_each_remove(void *value, void *user_data)
603{
604 Eina_Bench_Object *ebo = value;
605 Ecore_List *list = user_data;
606
607 if (ebo->keep == EINA_FALSE)
608 ecore_list_remove_destroy(list);
609}
610
611static void
612_eina_ecore_for_each_rand(void *value, __UNUSED__ void *user_data)
613{
614 Eina_Bench_Object *ebo = value;
615
616 ebo->keep = rand() < (RAND_MAX / 2) ? ebo->keep : EINA_FALSE;
617}
618
619static void
620eina_bench_ecore_list_4evas_render(int request)
621{
622 Ecore_List *list = NULL;
623 Eina_Bench_Object *ebo;
624 int i;
625 int j;
626
627 list = ecore_list_new();
628 ecore_list_free_cb_set(list, free);
629
630 for (i = 0; i < 1000; ++i)
631 {
632 for (j = 0; j < request; ++j)
633 {
634 ebo = malloc(sizeof (Eina_Bench_Object));
635 if (!ebo)
636 continue;
637
638 ebo->keep = rand() < (RAND_MAX / 2) ? EINA_TRUE : EINA_FALSE;
639
640 ecore_list_prepend(list, ebo);
641 }
642
643 if (i == 500)
644 ecore_list_clear(list);
645 else if (i % 30 == 0)
646 ecore_list_for_each(list, _eina_ecore_for_each_remove, list);
647
648 ecore_list_for_each(list, _eina_ecore_for_each_rand, list);
649 }
650
651 ecore_list_destroy(list);
652}
653
654void eina_bench_array(Eina_Benchmark *bench)
655{
656 eina_benchmark_register(bench, "array-inline",
657 EINA_BENCHMARK(
658 eina_bench_array_4evas_render_inline), 200,
659 4000, 100);
660 eina_benchmark_register(bench, "array-iterator",
661 EINA_BENCHMARK(
662 eina_bench_array_4evas_render_iterator), 200,
663 4000, 100);
664 eina_benchmark_register(bench, "list",
665 EINA_BENCHMARK(
666 eina_bench_list_4evas_render), 200,
667 4000, 100);
668 eina_benchmark_register(bench, "list-iterator",
669 EINA_BENCHMARK(
670 eina_bench_list_4evas_render_iterator), 200,
671 4000, 100);
672 eina_benchmark_register(bench, "inlist",
673 EINA_BENCHMARK(
674 eina_bench_inlist_4evas_render), 200,
675 4000, 100);
676 eina_benchmark_register(bench, "inlist-iterator",
677 EINA_BENCHMARK(
678 eina_bench_inlist_4evas_render_iterator), 200,
679 4000, 100);
680#ifdef EINA_BENCH_HAVE_GLIB
681 eina_benchmark_register(bench, "glist",
682 EINA_BENCHMARK(
683 eina_bench_glist_4evas_render), 200,
684 4000, 100);
685 eina_benchmark_register(bench, "gptrarray",
686 EINA_BENCHMARK(
687 eina_bench_gptrarray_4evas_render), 200,
688 4000, 100);
689#endif
690 eina_benchmark_register(bench, "evas",
691 EINA_BENCHMARK(
692 eina_bench_evas_list_4evas_render), 200,
693 4000, 100);
694 eina_benchmark_register(bench, "ecore",
695 EINA_BENCHMARK(
696 eina_bench_ecore_list_4evas_render), 200,
697 500, 100);
698}
699