efl
135 строк · 3.5 Кб
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 <limits.h>26
27#include "eina_bench.h"28#include "Eina.h"29
30typedef struct _Eina_Benchmark_Case Eina_Benchmark_Case;31struct _Eina_Benchmark_Case32{
33const char *bench_case;34void (*build)(Eina_Benchmark *bench);35Eina_Bool run_by_default;36};37
38static const Eina_Benchmark_Case etc[] = {39{ "Hash_Short_Key", eina_bench_crc_hash_short, EINA_TRUE },40{ "Hash_Medium_Key", eina_bench_crc_hash_medium, EINA_TRUE },41{ "Hash_Large_key", eina_bench_crc_hash_large, EINA_TRUE },42{ "Array vs List vs Inlist", eina_bench_array, EINA_TRUE },43{ "Stringshare", eina_bench_stringshare, EINA_TRUE },44{ "Convert", eina_bench_convert, EINA_TRUE },45{ "Sort", eina_bench_sort, EINA_TRUE },46{ "Mempool", eina_bench_mempool, EINA_TRUE },47{ "Rectangle_Pool", eina_bench_rectangle_pool, EINA_TRUE },48{ "Render Loop", eina_bench_quadtree, EINA_FALSE },49{ NULL, NULL, EINA_FALSE }50};51
52/* FIXME this is a copy from eina_test_mempool
53* we should remove the duplication
54*/
55static Eina_Array *_modules;56static void _mempool_init(void)57{
58eina_init();59/* force modules to be loaded in case they are not installed */60_modules = eina_module_list_get(NULL,61PACKAGE_BUILD_DIR "/src/modules/eina",62EINA_TRUE,63NULL,64NULL);65eina_module_list_load(_modules);66}
67
68static void _mempool_shutdown(void)69{
70eina_module_list_free(_modules);71if (_modules)72{73Eina_Array_Iterator it;74char* module;75unsigned int i;76
77EINA_ARRAY_ITER_NEXT(_modules, i, module, it)78free(module);79eina_array_free(_modules);80}81eina_shutdown();82}
83
84int
85main(int argc, char **argv)86{
87Eina_Benchmark *test;88unsigned int i;89
90_mempool_init();91
92eina_init();93
94switch (argc)95{96case 1:97for (i = 0; etc[i].bench_case; ++i)98if (etc[i].run_by_default)99{100test = eina_benchmark_new(etc[i].bench_case, "default");101if (!test) continue;102
103etc[i].build(test);104
105eina_benchmark_run(test);106
107eina_benchmark_free(test);108}109break;110case 2:111for (i = 0; etc[i].bench_case; ++i)112{113if (strcasecmp(etc[i].bench_case, argv[1]))114continue;115
116test = eina_benchmark_new(etc[i].bench_case, argv[1]);117if (!test)118continue;119
120etc[i].build(test);121
122eina_benchmark_run(test);123
124eina_benchmark_free(test);125
126break;127}128break;129}130
131eina_shutdown();132
133_mempool_shutdown();134return 0;135}
136