summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-04-12 23:12:52 +0000
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>2011-04-12 23:12:52 +0000
commitd422c0a88ed00a4a930de4c317507ec5cdb91343 (patch)
tree4ccbecda3e29bace43fd8294978e197690b965d9 /legacy/eina/src/tests/eina_bench_hash.c
parent09c490369a9155c732057dab21ed62214206239d (diff)
add bench for google's cityhash function (64bit, http://code.google.com/p/cityhash/)
convenient graph of output can be found at http://www.enlightenment.org/~discomfitor/hash_bench.png SVN revision: 58610
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
index aaabbb22c2..46feedc0a8 100644
--- a/legacy/eina/src/tests/eina_bench_hash.c
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -38,6 +38,28 @@
38#include "eina_rbtree.h" 38#include "eina_rbtree.h"
39#include "eina_convert.h" 39#include "eina_convert.h"
40 40
41#ifdef CITYHASH_BENCH
42// Hash function for a byte array.
43uint64_t CityHash64(const char *buf, size_t len);
44
45static unsigned int
46_eina_string_key_length(const char *key)
47{
48 if (!key)
49 return 0;
50
51 return (int)strlen(key) + 1;
52}
53
54static int
55_eina_string_key_cmp(const char *key1, __UNUSED__ int key1_length,
56 const char *key2, __UNUSED__ int key2_length)
57{
58 return strcmp(key1, key2);
59}
60#endif
61
62
41typedef struct _Eina_Bench_Rbtree Eina_Bench_Rbtree; 63typedef struct _Eina_Bench_Rbtree Eina_Bench_Rbtree;
42struct _Eina_Bench_Rbtree 64struct _Eina_Bench_Rbtree
43{ 65{
@@ -122,6 +144,51 @@ eina_bench_lookup_rbtree(int request)
122 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL); 144 eina_rbtree_delete(root, EINA_RBTREE_FREE_CB(_eina_bench_rbtree_free), NULL);
123} 145}
124 146
147#ifdef CITYHASH_BENCH
148static void
149eina_bench_lookup_cityhash(int request)
150{
151 Eina_Hash *hash = NULL;
152 int *tmp_val;
153 unsigned int i;
154 unsigned int j;
155
156 hash = eina_hash_new(EINA_KEY_LENGTH(_eina_string_key_length),
157 EINA_KEY_CMP(_eina_string_key_cmp),
158 EINA_KEY_HASH(CityHash64),
159 free,
160 8);
161
162 for (i = 0; i < (unsigned int)request; ++i)
163 {
164 char tmp_key[10];
165
166 tmp_val = malloc(sizeof (int));
167
168 if (!tmp_val)
169 continue;
170
171 eina_convert_itoa(i, tmp_key);
172 *tmp_val = i;
173
174 eina_hash_add(hash, tmp_key, tmp_val);
175 }
176
177 srand(time(NULL));
178
179 for (j = 0; j < 200; ++j)
180 for (i = 0; i < (unsigned int)request; ++i)
181 {
182 char tmp_key[10];
183
184 eina_convert_itoa(rand() % request, tmp_key);
185 tmp_val = eina_hash_find(hash, tmp_key);
186 }
187
188 eina_hash_free(hash);
189}
190#endif
191
125static void 192static void
126eina_bench_lookup_superfast(int request) 193eina_bench_lookup_superfast(int request)
127{ 194{
@@ -311,7 +378,7 @@ eina_bench_lookup_evas(int request)
311 unsigned int i; 378 unsigned int i;
312 unsigned int j; 379 unsigned int j;
313 380
314 array = eina_array_new(1000); 381 array = eina_array_new(10000);
315 382
316 for (i = 0; i < (unsigned int)request; ++i) 383 for (i = 0; i < (unsigned int)request; ++i)
317 { 384 {
@@ -409,6 +476,11 @@ void eina_bench_hash(Eina_Benchmark *bench)
409 eina_benchmark_register(bench, "djb2-lookup-inline", 476 eina_benchmark_register(bench, "djb2-lookup-inline",
410 EINA_BENCHMARK( 477 EINA_BENCHMARK(
411 eina_bench_lookup_djb2_inline), 10, 10000, 10); 478 eina_bench_lookup_djb2_inline), 10, 10000, 10);
479#ifdef CITYHASH_BENCH
480 eina_benchmark_register(bench, "cityhash",
481 EINA_BENCHMARK(
482 eina_bench_lookup_cityhash), 10, 10000, 10);
483#endif
412 eina_benchmark_register(bench, "rbtree", 484 eina_benchmark_register(bench, "rbtree",
413 EINA_BENCHMARK( 485 EINA_BENCHMARK(
414 eina_bench_lookup_rbtree), 10, 10000, 10); 486 eina_bench_lookup_rbtree), 10, 10000, 10);