diff --git a/legacy/eobj/CMakeLists.txt b/legacy/eobj/CMakeLists.txt index a466c6485e..8742a797b2 100644 --- a/legacy/eobj/CMakeLists.txt +++ b/legacy/eobj/CMakeLists.txt @@ -41,6 +41,7 @@ include(EFLCheck) add_subdirectory(src/lib) add_subdirectory(src/tests EXCLUDE_FROM_ALL) +add_subdirectory(src/benchmarks EXCLUDE_FROM_ALL) add_subdirectory(src/examples) add_subdirectory(doc) diff --git a/legacy/eobj/src/benchmarks/CMakeLists.txt b/legacy/eobj/src/benchmarks/CMakeLists.txt new file mode 100644 index 0000000000..84529d91fa --- /dev/null +++ b/legacy/eobj/src/benchmarks/CMakeLists.txt @@ -0,0 +1,26 @@ +LIST(APPEND EO_SUITE_CC_SOURCES + eo_bench.c + eo_bench_eo_do.c + class_simple.c + ) + +add_executable(eo_bench ${EO_SUITE_CC_SOURCES}) + +include_directories( + ${EINA_INCLUDE_DIRS} + ${CMAKE_SOURCE_DIR}/src/lib + ) + +get_target_property(eo_LIB_FILE eo LOCATION) +target_link_libraries(eo_bench + ${EINA_LIBRARIES} + ${EINA_LDFLAGS_OTHER} + ${eo_LIB_FILE} + ) + +add_dependencies(eo_bench eo) + +get_target_property(eo_bench_EXEC_FILE eo_bench LOCATION) +add_custom_target(benchmark COMMAND ${eo_bench_EXEC_FILE} eo_bench) + +add_dependencies(benchmark eo_bench) diff --git a/legacy/eobj/src/benchmarks/class_simple.c b/legacy/eobj/src/benchmarks/class_simple.c new file mode 100644 index 0000000000..6492d91b62 --- /dev/null +++ b/legacy/eobj/src/benchmarks/class_simple.c @@ -0,0 +1,48 @@ +#include "Eo.h" +#include "class_simple.h" + +#include "config.h" + +#define MY_CLASS SIMPLE_CLASS + +EAPI Eo_Op SIMPLE_BASE_ID = 0; + +static void +_a_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list) +{ + Simple_Public_Data *pd = class_data; + int a; + a = va_arg(*list, int); + + pd->a = a; +} + +static void +_class_constructor(Eo_Class *klass) +{ + const Eo_Op_Func_Description func_desc[] = { + EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set), + EO_OP_FUNC_SENTINEL + }; + + eo_class_funcs_set(klass, func_desc); +} + +static const Eo_Op_Description op_desc[] = { + EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"), + EO_OP_DESCRIPTION_SENTINEL +}; + +static const Eo_Class_Description class_desc = { + EO_VERSION, + "Simple", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST), + NULL, + sizeof(Simple_Public_Data), + _class_constructor, + NULL +}; + +EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL) + diff --git a/legacy/eobj/src/benchmarks/class_simple.h b/legacy/eobj/src/benchmarks/class_simple.h new file mode 100644 index 0000000000..86f07a1c07 --- /dev/null +++ b/legacy/eobj/src/benchmarks/class_simple.h @@ -0,0 +1,25 @@ +#ifndef SIMPLE_H +#define SIMPLE_H + +#include "Eo.h" + +extern EAPI Eo_Op SIMPLE_BASE_ID; + +enum { + SIMPLE_SUB_ID_A_SET, + SIMPLE_SUB_ID_LAST +}; + +typedef struct +{ + int a; +} Simple_Public_Data; + +#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id) + +#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a) + +#define SIMPLE_CLASS simple_class_get() +const Eo_Class *simple_class_get(void); + +#endif diff --git a/legacy/eobj/src/benchmarks/eo_bench.c b/legacy/eobj/src/benchmarks/eo_bench.c new file mode 100644 index 0000000000..580f744f1a --- /dev/null +++ b/legacy/eobj/src/benchmarks/eo_bench.c @@ -0,0 +1,53 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include +#include +#include + +#include "Eo.h" +#include "eo_bench.h" + +typedef struct _Eina_Benchmark_Case Eina_Benchmark_Case; +struct _Eina_Benchmark_Case +{ + const char *bench_case; + void (*build)(Eina_Benchmark *bench); +}; + +static const Eina_Benchmark_Case etc[] = { + { "Eo_Do", eo_bench_eo_do }, + { NULL, NULL } +}; + +int +main(int argc, char **argv) +{ + Eina_Benchmark *test; + unsigned int i; + + if (argc != 2) + return -1; + + eina_init(); + eo_init(); + + for (i = 0; etc[i].bench_case; ++i) + { + test = eina_benchmark_new(etc[i].bench_case, argv[1]); + if (!test) + continue; + + etc[i].build(test); + + eina_benchmark_run(test); + + eina_benchmark_free(test); + } + + eo_shutdown(); + eina_shutdown(); + + return 0; +} diff --git a/legacy/eobj/src/benchmarks/eo_bench.h b/legacy/eobj/src/benchmarks/eo_bench.h new file mode 100644 index 0000000000..f55f1c3e58 --- /dev/null +++ b/legacy/eobj/src/benchmarks/eo_bench.h @@ -0,0 +1,9 @@ +#ifndef EINA_BENCH_H_ +#define EINA_BENCH_H_ + +#include +#include + +void eo_bench_eo_do(Eina_Benchmark *bench); + +#endif diff --git a/legacy/eobj/src/benchmarks/eo_bench_eo_do.c b/legacy/eobj/src/benchmarks/eo_bench_eo_do.c new file mode 100644 index 0000000000..2b1991fa14 --- /dev/null +++ b/legacy/eobj/src/benchmarks/eo_bench_eo_do.c @@ -0,0 +1,27 @@ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "Eo.h" +#include "eo_bench.h" + +#include "class_simple.h" + +static void +bench_eo_do_general(int request) +{ + int i; + Eo *obj = eo_add(SIMPLE_CLASS, NULL); + for (i = 0 ; i < request ; i++) + { + eo_do(obj, simple_a_set(i)); + } + + eo_unref(obj); +} + +void eo_bench_eo_do(Eina_Benchmark *bench) +{ + eina_benchmark_register(bench, "general", + EINA_BENCHMARK(bench_eo_do_general), 100, 10000, 500); +}