aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/eina/src/tests/eina_bench_stringshare.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/eina/src/tests/eina_bench_stringshare.c')
-rw-r--r--libraries/eina/src/tests/eina_bench_stringshare.c177
1 files changed, 177 insertions, 0 deletions
diff --git a/libraries/eina/src/tests/eina_bench_stringshare.c b/libraries/eina/src/tests/eina_bench_stringshare.c
new file mode 100644
index 0000000..a2c7b38
--- /dev/null
+++ b/libraries/eina/src/tests/eina_bench_stringshare.c
@@ -0,0 +1,177 @@
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 <stdio.h>
25#include <time.h>
26
27#ifdef EINA_BENCH_HAVE_GLIB
28# include <glib.h>
29#endif
30
31#include "Evas_Data.h"
32#include "Ecore_Data.h"
33
34#include "eina_stringshare.h"
35#include "eina_bench.h"
36#include "eina_convert.h"
37#include "eina_main.h"
38
39static void
40eina_bench_stringshare_job(int request)
41{
42 const char *tmp;
43 unsigned int j;
44 int i;
45
46 eina_init();
47
48 for (i = 0; i < request; ++i)
49 {
50 char build[64] = "string_";
51
52 eina_convert_xtoa(i, build + 7);
53 tmp = eina_stringshare_add(build);
54 }
55
56 srand(time(NULL));
57
58 for (j = 0; j < 200; ++j)
59 for (i = 0; i < request; ++i)
60 {
61 char build[64] = "string_";
62
63 eina_convert_xtoa(rand() % request, build + 7);
64 tmp = eina_stringshare_add(build);
65 }
66
67 eina_shutdown();
68}
69
70#ifdef EINA_BENCH_HAVE_GLIB
71static void
72eina_bench_stringchunk_job(int request)
73{
74 GStringChunk *chunk;
75 unsigned int j;
76 int i;
77
78 chunk = g_string_chunk_new(4096);
79
80 for (i = 0; i < request; ++i)
81 {
82 char build[64] = "string_";
83
84 eina_convert_xtoa(i, build + 7);
85 g_string_chunk_insert_const(chunk, build);
86 }
87
88 srand(time(NULL));
89
90 for (j = 0; j < 200; ++j)
91 for (i = 0; i < request; ++i)
92 {
93 char build[64] = "string_";
94
95 eina_convert_xtoa(rand() % request, build + 7);
96 g_string_chunk_insert_const(chunk, build);
97 }
98
99 g_string_chunk_free(chunk);
100}
101#endif
102
103static void
104eina_bench_evas_job(int request)
105{
106 const char *tmp;
107 unsigned int j;
108 int i;
109
110 for (i = 0; i < request; ++i)
111 {
112 char build[64] = "string_";
113
114 eina_convert_xtoa(i, build + 7);
115 tmp = evas_stringshare_add(build);
116 }
117
118 srand(time(NULL));
119
120 for (j = 0; j < 200; ++j)
121 for (i = 0; i < request; ++i)
122 {
123 char build[64] = "string_";
124
125 eina_convert_xtoa(rand() % request, build + 7);
126 tmp = evas_stringshare_add(build);
127 }
128}
129
130static void
131eina_bench_ecore_job(int request)
132{
133 const char *tmp;
134 unsigned int j;
135 int i;
136
137 ecore_string_init();
138
139 for (i = 0; i < request; ++i)
140 {
141 char build[64] = "string_";
142
143 eina_convert_xtoa(i, build + 7);
144 tmp = ecore_string_instance(build);
145 }
146
147 srand(time(NULL));
148
149 for (j = 0; j < 200; ++j)
150 for (i = 0; i < request; ++i)
151 {
152 char build[64] = "string_";
153
154 eina_convert_xtoa(rand() % request, build + 7);
155 tmp = ecore_string_instance(build);
156 }
157
158 ecore_string_shutdown();
159}
160
161void eina_bench_stringshare(Eina_Benchmark *bench)
162{
163 eina_benchmark_register(bench, "stringshare",
164 EINA_BENCHMARK(
165 eina_bench_stringshare_job), 100, 20100, 500);
166#ifdef EINA_BENCH_HAVE_GLIB
167 eina_benchmark_register(bench, "stringchunk (glib)",
168 EINA_BENCHMARK(
169 eina_bench_stringchunk_job), 100, 20100, 500);
170#endif
171 eina_benchmark_register(bench, "stringshare (evas)",
172 EINA_BENCHMARK(
173 eina_bench_evas_job), 100, 20100, 500);
174 eina_benchmark_register(bench, "stringshare (ecore)",
175 EINA_BENCHMARK(
176 eina_bench_ecore_job), 100, 20100, 500);
177}