1 /* EINA - EFL data type library
2 * Copyright (C) 2008 Cedric Bail
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.
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.
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/>.
27 #ifdef EINA_BENCH_HAVE_GLIB
31 #include "Evas_Data.h"
32 #include "Ecore_Data.h"
34 #include "eina_stringshare.h"
35 #include "eina_bench.h"
36 #include "eina_convert.h"
37 #include "eina_main.h"
40 eina_bench_stringshare_job(int request)
48 for (i = 0; i < request; ++i)
50 char build[64] = "string_";
52 eina_convert_xtoa(i, build + 7);
53 tmp = eina_stringshare_add(build);
58 for (j = 0; j < 200; ++j)
59 for (i = 0; i < request; ++i)
61 char build[64] = "string_";
63 eina_convert_xtoa(rand() % request, build + 7);
64 tmp = eina_stringshare_add(build);
67 /* Suppress warnings as we really don't want to do anything. */
72 #ifdef EINA_BENCH_HAVE_GLIB
74 eina_bench_stringchunk_job(int request)
80 chunk = g_string_chunk_new(4096);
82 for (i = 0; i < request; ++i)
84 char build[64] = "string_";
86 eina_convert_xtoa(i, build + 7);
87 g_string_chunk_insert_const(chunk, build);
92 for (j = 0; j < 200; ++j)
93 for (i = 0; i < request; ++i)
95 char build[64] = "string_";
97 eina_convert_xtoa(rand() % request, build + 7);
98 g_string_chunk_insert_const(chunk, build);
101 g_string_chunk_free(chunk);
106 eina_bench_evas_job(int request)
112 for (i = 0; i < request; ++i)
114 char build[64] = "string_";
116 eina_convert_xtoa(i, build + 7);
117 tmp = evas_stringshare_add(build);
122 for (j = 0; j < 200; ++j)
123 for (i = 0; i < request; ++i)
125 char build[64] = "string_";
127 eina_convert_xtoa(rand() % request, build + 7);
128 tmp = evas_stringshare_add(build);
131 /* Suppress warnings as we really don't want to do anything. */
136 eina_bench_ecore_job(int request)
144 for (i = 0; i < request; ++i)
146 char build[64] = "string_";
148 eina_convert_xtoa(i, build + 7);
149 tmp = ecore_string_instance(build);
154 for (j = 0; j < 200; ++j)
155 for (i = 0; i < request; ++i)
157 char build[64] = "string_";
159 eina_convert_xtoa(rand() % request, build + 7);
160 tmp = ecore_string_instance(build);
163 /* Suppress warnings as we really don't want to do anything. */
166 ecore_string_shutdown();
169 void eina_bench_stringshare(Eina_Benchmark *bench)
171 eina_benchmark_register(bench, "stringshare",
173 eina_bench_stringshare_job), 100, 20100, 500);
174 #ifdef EINA_BENCH_HAVE_GLIB
175 eina_benchmark_register(bench, "stringchunk (glib)",
177 eina_bench_stringchunk_job), 100, 20100, 500);
179 eina_benchmark_register(bench, "stringshare (evas)",
181 eina_bench_evas_job), 100, 20100, 500);
182 eina_benchmark_register(bench, "stringshare (ecore)",
184 eina_bench_ecore_job), 100, 20100, 500);