diff options
author | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-01-04 18:41:13 +1000 |
commit | dd7595a3475407a7fa96a97393bae8c5220e8762 (patch) | |
tree | e341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/eina/src/tests/eina_bench_sort.c | |
parent | Add the skeleton. (diff) | |
download | SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2 SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz |
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to 'libraries/eina/src/tests/eina_bench_sort.c')
-rw-r--r-- | libraries/eina/src/tests/eina_bench_sort.c | 222 |
1 files changed, 222 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_bench_sort.c b/libraries/eina/src/tests/eina_bench_sort.c new file mode 100644 index 0000000..c3c9d9f --- /dev/null +++ b/libraries/eina/src/tests/eina_bench_sort.c | |||
@@ -0,0 +1,222 @@ | |||
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 <string.h> | ||
25 | |||
26 | #ifdef EINA_BENCH_HAVE_GLIB | ||
27 | # include <glib.h> | ||
28 | #endif | ||
29 | |||
30 | #include "Evas_Data.h" | ||
31 | #include "Ecore_Data.h" | ||
32 | |||
33 | #include "eina_bench.h" | ||
34 | #include "eina_convert.h" | ||
35 | #include "eina_list.h" | ||
36 | #include "eina_main.h" | ||
37 | |||
38 | static int | ||
39 | _eina_cmp_str(const char *a, const char *b) | ||
40 | { | ||
41 | return strcmp(a, b); | ||
42 | } | ||
43 | |||
44 | static void | ||
45 | eina_bench_sort_eina(int request) | ||
46 | { | ||
47 | Eina_List *list = NULL; | ||
48 | int i; | ||
49 | |||
50 | eina_init(); | ||
51 | |||
52 | srand(time(NULL)); | ||
53 | |||
54 | for (i = 0; i < request; ++i) | ||
55 | { | ||
56 | char buffer[10]; | ||
57 | |||
58 | eina_convert_itoa(rand() % request, buffer); | ||
59 | |||
60 | list = eina_list_prepend(list, strdup(buffer)); | ||
61 | } | ||
62 | |||
63 | list = eina_list_sort(list, -1, EINA_COMPARE_CB(_eina_cmp_str)); | ||
64 | |||
65 | while (list) | ||
66 | { | ||
67 | free(eina_list_data_get(list)); | ||
68 | list = eina_list_remove_list(list, list); | ||
69 | } | ||
70 | |||
71 | eina_shutdown(); | ||
72 | } | ||
73 | |||
74 | static void | ||
75 | eina_bench_sort_evas(int request) | ||
76 | { | ||
77 | Evas_List *list = NULL; | ||
78 | int i; | ||
79 | |||
80 | srand(time(NULL)); | ||
81 | |||
82 | for (i = 0; i < request; ++i) | ||
83 | { | ||
84 | char buffer[10]; | ||
85 | |||
86 | eina_convert_itoa(rand() % request, buffer); | ||
87 | |||
88 | list = evas_list_prepend(list, strdup(buffer)); | ||
89 | } | ||
90 | |||
91 | list = evas_list_sort(list, -1, (void *)_eina_cmp_str); | ||
92 | |||
93 | while (list) | ||
94 | { | ||
95 | free(evas_list_data(list)); | ||
96 | list = evas_list_remove_list(list, list); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | #ifdef EINA_BENCH_HAVE_GLIB | ||
101 | static void | ||
102 | eina_bench_sort_glist(int request) | ||
103 | { | ||
104 | GList *list = NULL; | ||
105 | int i; | ||
106 | |||
107 | srand(time(NULL)); | ||
108 | |||
109 | for (i = 0; i < request; ++i) | ||
110 | { | ||
111 | char buffer[10]; | ||
112 | |||
113 | eina_convert_itoa(rand() % request, buffer); | ||
114 | |||
115 | list = g_list_prepend(list, strdup(buffer)); | ||
116 | } | ||
117 | |||
118 | list = g_list_sort(list, (void *)_eina_cmp_str); | ||
119 | |||
120 | while (list) | ||
121 | { | ||
122 | free(list->data); | ||
123 | list = g_list_delete_link(list, list); | ||
124 | } | ||
125 | } | ||
126 | #endif | ||
127 | |||
128 | static void | ||
129 | eina_bench_sort_ecore_default(int request) | ||
130 | { | ||
131 | Ecore_List *list = NULL; | ||
132 | int i; | ||
133 | |||
134 | list = ecore_list_new(); | ||
135 | ecore_list_free_cb_set(list, free); | ||
136 | |||
137 | for (i = 0; i < request; ++i) | ||
138 | { | ||
139 | char buffer[10]; | ||
140 | |||
141 | eina_convert_itoa(rand() % request, buffer); | ||
142 | |||
143 | ecore_list_prepend(list, strdup(buffer)); | ||
144 | } | ||
145 | |||
146 | ecore_list_sort(list, ECORE_COMPARE_CB(_eina_cmp_str), 0); | ||
147 | |||
148 | ecore_list_destroy(list); | ||
149 | } | ||
150 | |||
151 | static void | ||
152 | eina_bench_sort_ecore_merge(int request) | ||
153 | { | ||
154 | Ecore_List *list = NULL; | ||
155 | int i; | ||
156 | |||
157 | list = ecore_list_new(); | ||
158 | ecore_list_free_cb_set(list, free); | ||
159 | |||
160 | for (i = 0; i < request; ++i) | ||
161 | { | ||
162 | char buffer[10]; | ||
163 | |||
164 | eina_convert_itoa(rand() % request, buffer); | ||
165 | |||
166 | ecore_list_prepend(list, strdup(buffer)); | ||
167 | } | ||
168 | |||
169 | ecore_list_mergesort(list, ECORE_COMPARE_CB(_eina_cmp_str), 0); | ||
170 | |||
171 | ecore_list_destroy(list); | ||
172 | } | ||
173 | |||
174 | static void | ||
175 | eina_bench_sort_ecore_heap(int request) | ||
176 | { | ||
177 | Ecore_List *list = NULL; | ||
178 | int i; | ||
179 | |||
180 | list = ecore_list_new(); | ||
181 | ecore_list_free_cb_set(list, free); | ||
182 | |||
183 | for (i = 0; i < request; ++i) | ||
184 | { | ||
185 | char buffer[10]; | ||
186 | |||
187 | eina_convert_itoa(rand() % request, buffer); | ||
188 | |||
189 | ecore_list_prepend(list, strdup(buffer)); | ||
190 | } | ||
191 | |||
192 | ecore_list_heapsort(list, ECORE_COMPARE_CB(_eina_cmp_str), 0); | ||
193 | |||
194 | ecore_list_destroy(list); | ||
195 | } | ||
196 | |||
197 | void eina_bench_sort(Eina_Benchmark *bench) | ||
198 | { | ||
199 | eina_benchmark_register(bench, "eina", | ||
200 | EINA_BENCHMARK( | ||
201 | eina_bench_sort_eina), 10, 10000, 100); | ||
202 | #ifdef EINA_BENCH_HAVE_GLIB | ||
203 | eina_benchmark_register(bench, "glist", | ||
204 | EINA_BENCHMARK( | ||
205 | eina_bench_sort_glist), 10, 10000, 100); | ||
206 | #endif | ||
207 | eina_benchmark_register(bench, "ecore", | ||
208 | EINA_BENCHMARK( | ||
209 | eina_bench_sort_ecore_default), 10, 10000, 100); | ||
210 | eina_benchmark_register(bench, "ecore-merge", | ||
211 | EINA_BENCHMARK( | ||
212 | eina_bench_sort_ecore_merge), 10, 10000, 100); | ||
213 | eina_benchmark_register(bench, "ecore-heap", | ||
214 | EINA_BENCHMARK( | ||
215 | eina_bench_sort_ecore_heap), 10, 10000, 100); | ||
216 | eina_benchmark_register(bench, "evas", | ||
217 | EINA_BENCHMARK( | ||
218 | eina_bench_sort_evas), 10, 10000, 100); | ||
219 | } | ||
220 | |||
221 | |||
222 | |||