Eo benchmarks: Add basic callbacks benchmarks.

This commit is contained in:
Tom Hacohen 2015-10-14 15:03:33 +01:00
parent 862372ed23
commit 4bf0f6455d
6 changed files with 97 additions and 0 deletions

View File

@ -18,6 +18,7 @@ class_simple.c \
class_simple.h \
eo_bench.c \
eo_bench.h \
eo_bench_callbacks.c \
eo_bench_eo_do.c \
eo_bench_eo_add.c

View File

@ -7,6 +7,9 @@
#define MY_CLASS SIMPLE_CLASS
EOAPI const Eo_Event_Description _SIMPLE_FOO = EO_EVENT_DESCRIPTION("foo");
EOAPI const Eo_Event_Description _SIMPLE_BAR = EO_EVENT_DESCRIPTION("bar");
static void
_other_call(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, Eo *other, int times)
{

View File

@ -14,4 +14,10 @@ EAPI void simple_other_call(Eo *other, int times);
#define SIMPLE_CLASS simple_class_get()
const Eo_Class *simple_class_get(void);
EOAPI extern const Eo_Event_Description _SIMPLE_FOO;
EOAPI extern const Eo_Event_Description _SIMPLE_BAR;
#define SIMPLE_FOO (&(_SIMPLE_FOO))
#define SIMPLE_BAR (&(_SIMPLE_BAR))
#endif

View File

@ -21,6 +21,7 @@ struct _Eina_Benchmark_Case
static const Eina_Benchmark_Case etc[] = {
{ "eo_do", eo_bench_eo_do },
{ "eo_add", eo_bench_eo_add },
{ "eo_callbacks", eo_bench_callbacks },
{ NULL, NULL }
};

View File

@ -3,6 +3,7 @@
void eo_bench_eo_do(Eina_Benchmark *bench);
void eo_bench_eo_add(Eina_Benchmark *bench);
void eo_bench_callbacks(Eina_Benchmark *bench);
#define _EO_BENCH_TIMES(Start, Repeat, Jump) (Start), ((Start) + ((Jump) * (Repeat))), (Jump)

View File

@ -0,0 +1,85 @@
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "Eo.h"
#include "eo_bench.h"
#include "class_simple.h"
static Eina_Bool
_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
{
return EO_CALLBACK_CONTINUE;
}
static void
bench_eo_callbacks_add(int request)
{
int i;
Eo *obj = eo_add(SIMPLE_CLASS, NULL);
for (i = 0 ; i < request ; i++)
{
eo_do(obj, eo_event_callback_priority_add(SIMPLE_FOO, (short) i, _cb, NULL));
}
eo_unref(obj);
}
static void
bench_eo_callbacks_call(int request)
{
/* Distribution of calls per amount of callbacks in an object as recorded by
running the genlist elementary_test test. */
const double distribution[] = {
0.2920468197,
0.2073086496,
0.217699456,
0.0207158285,
0.019707134,
0.0359433565,
0.0324896742,
0.0104299639,
0.028989003,
0.0082496801,
0.123214227,
0.0001331351,
0.0030730724
};
const int len = EINA_C_ARRAY_LENGTH(distribution);
int i, j;
Eo *obj[len] = { 0 };
for (i = 0 ; i < len ; i++)
{
obj[i] = eo_add(SIMPLE_CLASS, NULL);
for (j = 0 ; j < i ; j++)
{
eo_do(obj[i], eo_event_callback_priority_add(SIMPLE_FOO, (short) j, _cb, NULL));
}
}
for (i = 0 ; i < len ; i++)
{
for (j = 0 ; j < (int) (distribution[i] * request) ; j++)
{
/* Miss finding the callbacks on purpose, so we measure worst case scenario. */
eo_do(obj[i], eo_event_callback_call(SIMPLE_BAR, NULL));
}
}
for (i = 0 ; i < len ; i++)
{
eo_unref(obj[i]);
}
}
void eo_bench_callbacks(Eina_Benchmark *bench)
{
eina_benchmark_register(bench, "add",
EINA_BENCHMARK(bench_eo_callbacks_add), _EO_BENCH_TIMES(1000, 10, 2000));
eina_benchmark_register(bench, "call",
EINA_BENCHMARK(bench_eo_callbacks_call), _EO_BENCH_TIMES(100000, 10, 500000));
}