summaryrefslogtreecommitdiff
path: root/src/benchmarks
diff options
context:
space:
mode:
authorvivek <vivek.ellur@samsung.com>2015-04-28 23:29:18 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-05-07 09:53:11 +0200
commiteec4a7bd0caa7d52bff6cc524ca12efa16d1445b (patch)
tree786145e534cfb55b4a43e901cde65b0a75d7fe1a /src/benchmarks
parentd63593fc64be49f56857edecc540c94fac33c52a (diff)
eina: add benchmark for crc hash in eina benchmark
Summary: The code added is actually benchmarking all hash function key with various length (8, 32, 256 bytes). Signed-off-by: vivek <vivek.ellur@samsung.com> Reviewers: Sergeant_Whitespace, cedric Reviewed By: cedric Subscribers: Sergeant_Whitespace, cedric Differential Revision: https://phab.enlightenment.org/D2217 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/benchmarks')
-rw-r--r--src/benchmarks/eina/Makefile.am1
-rw-r--r--src/benchmarks/eina/eina_bench.c3
-rw-r--r--src/benchmarks/eina/eina_bench.h5
-rw-r--r--src/benchmarks/eina/eina_bench_crc_hash.c279
4 files changed, 288 insertions, 0 deletions
diff --git a/src/benchmarks/eina/Makefile.am b/src/benchmarks/eina/Makefile.am
index 9f64d46..da6ceb9 100644
--- a/src/benchmarks/eina/Makefile.am
+++ b/src/benchmarks/eina/Makefile.am
@@ -18,6 +18,7 @@ eina_bench_SOURCES = \
18eina_bench.c \ 18eina_bench.c \
19eina_bench_sort.c \ 19eina_bench_sort.c \
20eina_bench_hash.c \ 20eina_bench_hash.c \
21eina_bench_crc_hash.c \
21eina_bench_stringshare.c \ 22eina_bench_stringshare.c \
22eina_bench_convert.c \ 23eina_bench_convert.c \
23eina_bench_mempool.c \ 24eina_bench_mempool.c \
diff --git a/src/benchmarks/eina/eina_bench.c b/src/benchmarks/eina/eina_bench.c
index dec210e..1ca7e51 100644
--- a/src/benchmarks/eina/eina_bench.c
+++ b/src/benchmarks/eina/eina_bench.c
@@ -37,6 +37,9 @@ struct _Eina_Benchmark_Case
37 37
38static const Eina_Benchmark_Case etc[] = { 38static const Eina_Benchmark_Case etc[] = {
39 { "Hash", eina_bench_hash, EINA_TRUE }, 39 { "Hash", eina_bench_hash, EINA_TRUE },
40 { "Hash_Short_Key", eina_bench_crc_hash_short, EINA_TRUE },
41 { "Hash_Medium_Key", eina_bench_crc_hash_medium, EINA_TRUE },
42 { "Hash_Large_key", eina_bench_crc_hash_large, EINA_TRUE },
40 { "Array vs List vs Inlist", eina_bench_array, EINA_TRUE }, 43 { "Array vs List vs Inlist", eina_bench_array, EINA_TRUE },
41 { "Stringshare", eina_bench_stringshare, EINA_TRUE }, 44 { "Stringshare", eina_bench_stringshare, EINA_TRUE },
42 { "Convert", eina_bench_convert, EINA_TRUE }, 45 { "Convert", eina_bench_convert, EINA_TRUE },
diff --git a/src/benchmarks/eina/eina_bench.h b/src/benchmarks/eina/eina_bench.h
index d575822..f076d41 100644
--- a/src/benchmarks/eina/eina_bench.h
+++ b/src/benchmarks/eina/eina_bench.h
@@ -21,7 +21,12 @@
21 21
22#include "eina_benchmark.h" 22#include "eina_benchmark.h"
23 23
24int key_size;
25
24void eina_bench_hash(Eina_Benchmark *bench); 26void eina_bench_hash(Eina_Benchmark *bench);
27void eina_bench_crc_hash_short(Eina_Benchmark *bench);
28void eina_bench_crc_hash_medium(Eina_Benchmark *bench);
29void eina_bench_crc_hash_large(Eina_Benchmark *bench);
25void eina_bench_array(Eina_Benchmark *bench); 30void eina_bench_array(Eina_Benchmark *bench);
26void eina_bench_stringshare(Eina_Benchmark *bench); 31void eina_bench_stringshare(Eina_Benchmark *bench);
27void eina_bench_convert(Eina_Benchmark *bench); 32void eina_bench_convert(Eina_Benchmark *bench);
diff --git a/src/benchmarks/eina/eina_bench_crc_hash.c b/src/benchmarks/eina/eina_bench_crc_hash.c
new file mode 100644
index 0000000..b673448
--- /dev/null
+++ b/src/benchmarks/eina/eina_bench_crc_hash.c
@@ -0,0 +1,279 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include <stdlib.h>
6#include <stdio.h>
7#include <string.h>
8#include <time.h>
9
10#ifdef EINA_BENCH_HAVE_GLIB
11# include <glib.h>
12#endif
13
14#include <Eina.h>
15#include "Evas_Data.h"
16#include "Ecore_Data.h"
17
18#include "eina_hash.h"
19#include "eina_array.h"
20#include "eina_bench.h"
21#include "eina_rbtree.h"
22#include "eina_convert.h"
23
24#ifdef CITYHASH_BENCH
25// Hash function for a byte array.
26uint64_t CityHash64(const char *buf, size_t len);
27#endif
28
29char *key_str=NULL;
30
31void repchar(int n)
32{
33 key_str = (char *)malloc(n);
34 int i;
35
36 for (i = 0; i < n; i++)
37 key_str[i] = 'a';
38}
39
40static void
41eina_bench_murmur_hash(int request)
42{
43 unsigned int i;
44
45 for (i = 0; i < (unsigned int)request; ++i)
46 {
47 char tmp_key[key_size];
48
49 eina_convert_itoa(i, tmp_key);
50 eina_strlcat(tmp_key, key_str, key_size);
51
52 eina_hash_murmur3(tmp_key, key_size);
53 }
54}
55
56#ifdef CITYHASH_BENCH
57static void
58eina_bench_cityhash(int request)
59{
60 unsigned int i;
61
62 for (i = 0; i < (unsigned int)request; ++i)
63 {
64 char tmp_key[key_size];
65
66 eina_convert_itoa(i, tmp_key);
67 eina_strlcat(tmp_key, key_str, key_size);
68
69 CityHash64(tmp_key, key_size);
70 }
71}
72#endif
73
74static void
75eina_bench_superfast_hash(int request)
76{
77 unsigned int i;
78
79 for (i = 0; i < (unsigned int)request; ++i)
80 {
81 char tmp_key[key_size];
82
83 eina_convert_itoa(i, tmp_key);
84 eina_strlcat(tmp_key, key_str, key_size);
85
86 eina_hash_superfast(tmp_key, key_size);
87 }
88}
89
90static void
91eina_bench_crchash(int request)
92{
93 unsigned int i;
94
95 for (i = 0; i < (unsigned int)request; ++i)
96 {
97 char tmp_key[key_size];
98
99 eina_convert_itoa(i, tmp_key);
100 eina_strlcat(tmp_key, key_str, key_size);
101
102 eina_hash_crc(tmp_key, key_size);
103 }
104}
105
106static void
107eina_bench_djb2_hash(int request)
108{
109 unsigned int i;
110
111 for (i = 0; i < (unsigned int)request; ++i)
112 {
113 char tmp_key[key_size];
114
115 eina_convert_itoa(i, tmp_key);
116 eina_strlcat(tmp_key, key_str, key_size);
117
118 eina_hash_djb2(tmp_key, key_size);
119 }
120}
121
122#ifdef EINA_BENCH_HAVE_GLIB
123static void
124eina_bench_ghash(int request)
125{
126 unsigned int i;
127
128 for (i = 0; i < (unsigned int)request; ++i)
129 {
130 char tmp_key[key_size];
131
132 eina_convert_itoa(i, tmp_key);
133 eina_strlcat(tmp_key, key_str, key_size);
134
135 g_str_hash(key_str);
136 }
137}
138#endif
139
140int
141evas_hash_gen(const char *key)
142{
143 unsigned int hash_num = 5381;
144 const unsigned char *ptr;
145
146 if (!key)
147 return 0;
148
149 for (ptr = (unsigned char *)key; *ptr; ptr++)
150 hash_num = (hash_num * 33) ^ *ptr;
151
152 hash_num &= 0xff;
153 return (int)hash_num;
154}
155
156static void
157eina_bench_evas_hash(int request)
158{
159 unsigned int i;
160
161 for (i = 0; i < (unsigned int)request; ++i)
162 {
163 char tmp_key[key_size];
164
165 eina_convert_itoa(i, tmp_key);
166 eina_strlcat(tmp_key, key_str, key_size);
167
168 evas_hash_gen(tmp_key);
169 }
170}
171
172typedef struct _Eina_Bench_Ecore Eina_Bench_Ecore;
173struct _Eina_Bench_Ecore
174{
175 char *key;
176 int value;
177};
178
179void eina_bench_crc_hash_short(Eina_Benchmark *bench)
180{
181 key_size = 8; /* Length of string for small strings and pointers */
182 key_size -= 5;
183 repchar(key_size);
184
185 eina_benchmark_register(bench, "superfast-lookup",
186 EINA_BENCHMARK(
187 eina_bench_superfast_hash), 10, 80000, 10);
188 eina_benchmark_register(bench, "djb2-lookup",
189 EINA_BENCHMARK(
190 eina_bench_djb2_hash), 10, 80000, 10);
191 eina_benchmark_register(bench, "murmur",
192 EINA_BENCHMARK(
193 eina_bench_murmur_hash), 10, 80000, 10);
194 eina_benchmark_register(bench, "crchash",
195 EINA_BENCHMARK(
196 eina_bench_crchash), 10, 80000, 10);
197#ifdef CITYHASH_BENCH
198 eina_benchmark_register(bench, "cityhash",
199 EINA_BENCHMARK(
200 eina_bench_cityhash), 10, 80000, 10);
201#endif
202
203#ifdef EINA_BENCH_HAVE_GLIB
204 eina_benchmark_register(bench, "ghash-lookup",
205 EINA_BENCHMARK(
206 eina_bench_ghash), 10, 80000, 10);
207#endif
208 eina_benchmark_register(bench, "evas-lookup",
209 EINA_BENCHMARK(
210 eina_bench_evas_hash), 10, 80000, 10);
211}
212
213void eina_bench_crc_hash_medium(Eina_Benchmark *bench)
214{
215 key_size = 32; /* Length of medium sized string, normally for filenames */
216 key_size -= 5;
217 repchar(key_size);
218
219 eina_benchmark_register(bench, "superfast-lookup",
220 EINA_BENCHMARK(
221 eina_bench_superfast_hash), 10, 80000, 10);
222 eina_benchmark_register(bench, "djb2-lookup",
223 EINA_BENCHMARK(
224 eina_bench_djb2_hash), 10, 80000, 10);
225 eina_benchmark_register(bench, "murmur",
226 EINA_BENCHMARK(
227 eina_bench_murmur_hash), 10, 80000, 10);
228 eina_benchmark_register(bench, "crchash",
229 EINA_BENCHMARK(
230 eina_bench_crchash), 10, 80000, 10);
231#ifdef CITYHASH_BENCH
232 eina_benchmark_register(bench, "cityhash",
233 EINA_BENCHMARK(
234 eina_bench_cityhash), 10, 80000, 10);
235#endif
236
237#ifdef EINA_BENCH_HAVE_GLIB
238 eina_benchmark_register(bench, "ghash-lookup",
239 EINA_BENCHMARK(
240 eina_bench_ghash), 10, 80000, 10);
241#endif
242 eina_benchmark_register(bench, "evas-lookup",
243 EINA_BENCHMARK(
244 eina_bench_evas_hash), 10, 80000, 10);
245}
246
247void eina_bench_crc_hash_large(Eina_Benchmark *bench)
248{
249 key_size = 256; /* Length of large strings, normally for filepath */
250 key_size -= 5;
251 repchar(key_size);
252
253 eina_benchmark_register(bench, "superfast-lookup",
254 EINA_BENCHMARK(
255 eina_bench_superfast_hash), 10, 80000, 10);
256 eina_benchmark_register(bench, "djb2-lookup",
257 EINA_BENCHMARK(
258 eina_bench_djb2_hash), 10, 80000, 10);
259 eina_benchmark_register(bench, "murmur",
260 EINA_BENCHMARK(
261 eina_bench_murmur_hash), 10, 80000, 10);
262 eina_benchmark_register(bench, "crchash",
263 EINA_BENCHMARK(
264 eina_bench_crchash), 10, 80000, 10);
265#ifdef CITYHASH_BENCH
266 eina_benchmark_register(bench, "cityhash",
267 EINA_BENCHMARK(
268 eina_bench_cityhash), 10, 80000, 10);
269#endif
270
271#ifdef EINA_BENCH_HAVE_GLIB
272 eina_benchmark_register(bench, "ghash-lookup",
273 EINA_BENCHMARK(
274 eina_bench_ghash), 10, 80000, 10);
275#endif
276 eina_benchmark_register(bench, "evas-lookup",
277 EINA_BENCHMARK(
278 eina_bench_evas_hash), 10, 80000, 10);
279}