summaryrefslogtreecommitdiff
path: root/legacy/eina/src/tests/eina_bench_hash.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2008-08-06 15:54:56 +0000
committerCedric BAIL <cedric.bail@free.fr>2008-08-06 15:54:56 +0000
commitba3ee2cd1682576729b7c0fe77bf8b2b04cb813a (patch)
tree9c987ea531d037d8c77e320588664bb535115309 /legacy/eina/src/tests/eina_bench_hash.c
parent693f0eca8d2ab1caab3876ac51e56b78acd8f4f4 (diff)
Add benchmark support.
SVN revision: 35355
Diffstat (limited to '')
-rw-r--r--legacy/eina/src/tests/eina_bench_hash.c188
1 files changed, 188 insertions, 0 deletions
diff --git a/legacy/eina/src/tests/eina_bench_hash.c b/legacy/eina/src/tests/eina_bench_hash.c
new file mode 100644
index 0000000000..2dce462b3d
--- /dev/null
+++ b/legacy/eina/src/tests/eina_bench_hash.c
@@ -0,0 +1,188 @@
1#include <stdlib.h>
2#include <stdio.h>
3#include <string.h>
4#include <time.h>
5
6#include "eina_hash.h"
7#include "eina_array.h"
8#include "eina_bench.h"
9
10static void
11eina_bench_insert_superfast(int request)
12{
13 Eina_Hash *hash = NULL;
14 Eina_Array *array = NULL;
15 int *tmp_val;
16 unsigned int i;
17
18 array = eina_array_new(1000);
19
20 hash = eina_hash_string_superfast_new();
21
22 for (i = 0; i < (unsigned int) request; ++i)
23 {
24 char *tmp_key = malloc(10);
25
26 tmp_val = malloc(sizeof (int));
27
28 if (!tmp_key || !tmp_val) continue ;
29
30 snprintf(tmp_key, 10, "%i", i);
31 *tmp_val = i;
32
33 eina_hash_add(hash, tmp_key, tmp_val);
34
35 eina_array_append(array, tmp_val);
36
37 free(tmp_key);
38 }
39
40 eina_hash_free(hash);
41
42 EINA_ARRAY_ITER_NEXT(array, i, tmp_val)
43 free(tmp_val);
44
45 eina_array_free(array);
46}
47
48static void
49eina_bench_insert_djb2(int request)
50{
51 Eina_Hash *hash = NULL;
52 Eina_Array *array = NULL;
53 int *tmp_val;
54 unsigned int i;
55
56 array = eina_array_new(1000);
57
58 hash = eina_hash_string_djb2_new();
59
60 for (i = 0; i < (unsigned int) request; ++i)
61 {
62 char *tmp_key = malloc(10);
63
64 tmp_val = malloc(sizeof (int));
65
66 if (!tmp_key || !tmp_val) continue ;
67
68 snprintf(tmp_key, 10, "%i", i);
69 *tmp_val = i;
70
71 eina_hash_add(hash, tmp_key, tmp_val);
72
73 eina_array_append(array, tmp_val);
74
75 free(tmp_key);
76 }
77
78 eina_hash_free(hash);
79
80 EINA_ARRAY_ITER_NEXT(array, i, tmp_val)
81 free(tmp_val);
82
83 eina_array_free(array);
84}
85
86static void
87eina_bench_lookup_superfast(int request)
88{
89 Eina_Hash *hash = NULL;
90 Eina_Array *array = NULL;
91 int *tmp_val;
92 unsigned int i;
93
94 array = eina_array_new(1000);
95
96 hash = eina_hash_string_superfast_new();
97
98 for (i = 0; i < (unsigned int) request; ++i)
99 {
100 char tmp_key[10];
101
102 tmp_val = malloc(sizeof (int));
103
104 if (!tmp_val) continue ;
105
106 snprintf(tmp_key, 10, "%i", i);
107 *tmp_val = i;
108
109 eina_hash_add(hash, tmp_key, tmp_val);
110
111 eina_array_append(array, tmp_val);
112 }
113
114 srand(time(NULL));
115
116 for (i = 0; i < (unsigned int) request; ++i)
117 {
118 char tmp_key[10];
119
120 snprintf(tmp_key, 10, "%i", rand() % request);
121
122 tmp_val = eina_hash_find(hash, tmp_key);
123 }
124
125 eina_hash_free(hash);
126
127 EINA_ARRAY_ITER_NEXT(array, i, tmp_val)
128 free(tmp_val);
129
130 eina_array_free(array);
131}
132
133static void
134eina_bench_lookup_djb2(int request)
135{
136 Eina_Hash *hash = NULL;
137 Eina_Array *array = NULL;
138 int *tmp_val;
139 unsigned int i;
140
141 array = eina_array_new(1000);
142
143 hash = eina_hash_string_djb2_new();
144
145 for (i = 0; i < (unsigned int) request; ++i)
146 {
147 char *tmp_key = malloc(10);
148
149 tmp_val = malloc(sizeof (int));
150
151 if (!tmp_key || !tmp_val) continue ;
152
153 snprintf(tmp_key, 10, "%i", i);
154 *tmp_val = i;
155
156 eina_hash_add(hash, tmp_key, tmp_val);
157
158 eina_array_append(array, tmp_val);
159
160 free(tmp_key);
161 }
162
163 srand(time(NULL));
164
165 for (i = 0; i < (unsigned int) request; ++i)
166 {
167 char tmp_key[10];
168
169 snprintf(tmp_key, 10, "%i", rand() % request);
170
171 tmp_val = eina_hash_find(hash, tmp_key);
172 }
173
174 eina_hash_free(hash);
175
176 EINA_ARRAY_ITER_NEXT(array, i, tmp_val)
177 free(tmp_val);
178
179 eina_array_free(array);
180}
181
182void eina_bench_hash(Eina_Bench *bench)
183{
184 eina_bench_register(bench, "superfast-insert", EINA_BENCH(eina_bench_insert_superfast), 1000, 180000, 2500);
185 eina_bench_register(bench, "djb2-insert", EINA_BENCH(eina_bench_insert_djb2), 1000, 180000, 2500);
186 eina_bench_register(bench, "superfast-lookup", EINA_BENCH(eina_bench_lookup_superfast), 1000, 180000, 2500);
187 eina_bench_register(bench, "djb2-lookup", EINA_BENCH(eina_bench_lookup_djb2), 1000, 180000, 2500);
188}