summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-08-27 17:14:34 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-08-27 17:14:34 +0000
commit1d3013e37d083955dd84c5d0be70c6860412b185 (patch)
treefafe0bb03c9a5df27e7f68f8820907b0bfe71a62 /legacy/eina/src/tests/eina_bench_hash.c
parent5a9be377b1ce3b2f3f7870dbe72df11ea6f79651 (diff)
Add benchmark against glib so we see where we stand.
SVN revision: 35699
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index a47e8ce65c..72f3732bce 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -16,11 +16,19 @@
16 * if not, see <http://www.gnu.org/licenses/>. 16 * if not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
19#include <stdlib.h> 23#include <stdlib.h>
20#include <stdio.h> 24#include <stdio.h>
21#include <string.h> 25#include <string.h>
22#include <time.h> 26#include <time.h>
23 27
28#ifdef EINA_BENCH_HAVE_GLIB
29#include <glib.h>
30#endif
31
24#include "eina_hash.h" 32#include "eina_hash.h"
25#include "eina_array.h" 33#include "eina_array.h"
26#include "eina_bench.h" 34#include "eina_bench.h"
@@ -219,9 +227,57 @@ eina_bench_lookup_djb2_inline(int request)
219 eina_array_free(array); 227 eina_array_free(array);
220} 228}
221 229
230#ifdef EINA_BENCH_HAVE_GLIB
231typedef struct _Eina_Bench_Glib Eina_Bench_Glib;
232struct _Eina_Bench_Glib
233{
234 char *key;
235 int value;
236};
237
238static void
239eina_bench_lookup_ghash(int request)
240{
241 Eina_Bench_Glib *elm;
242 GHashTable *hash;
243 unsigned int i;
244
245 hash = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free);
246
247 for (i = 0; i < (unsigned int) request; ++i)
248 {
249 elm = malloc(sizeof (Eina_Bench_Glib) + 10);
250 if (!elm) continue ;
251
252 elm->key = (char*) (elm + 1);
253
254 snprintf(elm->key, 10, "%i", i);
255 elm->value = i;
256
257 g_hash_table_insert(hash, elm->key, elm);
258 }
259
260 srand(time(NULL));
261
262 for (i = 0; i < (unsigned int) request; ++i)
263 {
264 char tmp_key[10];
265
266 snprintf(tmp_key, 10, "%i", rand() % request);
267
268 elm = g_hash_table_lookup(hash, tmp_key);
269 }
270
271 g_hash_table_destroy(hash);
272}
273#endif
274
222void eina_bench_hash(Eina_Bench *bench) 275void eina_bench_hash(Eina_Bench *bench)
223{ 276{
224 eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500); 277 eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500);
225 eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500); 278 eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500);
226 eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500); 279 eina_bench_register(bench, "djb2-lookup-inline", EINA_BENCH(eina_bench_lookup_djb2_inline), 1000, 180000, 2500);
280#ifdef EINA_BENCH_HAVE_GLIB
281 eina_bench_register(bench, "ghash-lookup", EINA_BENCH(eina_bench_lookup_ghash), 1000, 180000, 2500);
282#endif
227} 283}