efl
177 строк · 4.2 Кб
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_H20# include "config.h"21#endif22
23#include <stdlib.h>24#include <stdio.h>25#include <time.h>26
27#ifdef EINA_BENCH_HAVE_GLIB28# include <glib.h>29#endif30
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 void40eina_bench_stringshare_job(int request)41{
42const char *tmp;43unsigned int j;44int i;45
46eina_init();47
48for (i = 0; i < request; ++i)49{50char build[64] = "string_";51
52eina_convert_xtoa(i, build + 7);53tmp = eina_stringshare_add(build);54}55
56for (j = 0; j < 200; ++j)57for (i = 0; i < request; ++i)58{59char build[64] = "string_";60
61eina_convert_xtoa(rand() % request, build + 7);62tmp = eina_stringshare_add(build);63}64
65/* Suppress warnings as we really don't want to do anything. */66(void) tmp;67eina_shutdown();68}
69
70#ifdef EINA_BENCH_HAVE_GLIB71static void72eina_bench_stringchunk_job(int request)73{
74GStringChunk *chunk;75unsigned int j;76int i;77
78chunk = g_string_chunk_new(4096);79
80for (i = 0; i < request; ++i)81{82char build[64] = "string_";83
84eina_convert_xtoa(i, build + 7);85g_string_chunk_insert_const(chunk, build);86}87
88for (j = 0; j < 200; ++j)89for (i = 0; i < request; ++i)90{91char build[64] = "string_";92
93eina_convert_xtoa(rand() % request, build + 7);94g_string_chunk_insert_const(chunk, build);95}96
97g_string_chunk_free(chunk);98}
99#endif100
101static void102eina_bench_evas_job(int request)103{
104const char *tmp;105unsigned int j;106int i;107
108for (i = 0; i < request; ++i)109{110char build[64] = "string_";111
112eina_convert_xtoa(i, build + 7);113tmp = evas_stringshare_add(build);114}115
116for (j = 0; j < 200; ++j)117for (i = 0; i < request; ++i)118{119char build[64] = "string_";120
121eina_convert_xtoa(rand() % request, build + 7);122tmp = evas_stringshare_add(build);123}124
125/* Suppress warnings as we really don't want to do anything. */126(void) tmp;127}
128
129static void130eina_bench_ecore_job(int request)131{
132const char *tmp;133unsigned int j;134int i;135
136//ecore_string_init();137
138for (i = 0; i < request; ++i)139{140char build[64] = "string_";141
142eina_convert_xtoa(i, build + 7);143//tmp = ecore_string_instance(build);144}145
146for (j = 0; j < 200; ++j)147for (i = 0; i < request; ++i)148{149char build[64] = "string_";150
151eina_convert_xtoa(rand() % request, build + 7);152//tmp = ecore_string_instance(build);153}154
155/* Suppress warnings as we really don't want to do anything. */156(void) tmp;157
158//ecore_string_shutdown();159}
160
161void eina_bench_stringshare(Eina_Benchmark *bench)162{
163eina_benchmark_register(bench, "stringshare",164EINA_BENCHMARK(165eina_bench_stringshare_job), 100, 20100, 500);166#ifdef EINA_BENCH_HAVE_GLIB167eina_benchmark_register(bench, "stringchunk (glib)",168EINA_BENCHMARK(169eina_bench_stringchunk_job), 100, 20100, 500);170#endif171eina_benchmark_register(bench, "stringshare (evas)",172EINA_BENCHMARK(173eina_bench_evas_job), 100, 20100, 500);174eina_benchmark_register(bench, "stringshare (ecore)",175EINA_BENCHMARK(176eina_bench_ecore_job), 100, 20100, 500);177}
178