summaryrefslogtreecommitdiff
path: root/src/benchmarks/eo/eo_bench_callbacks.c
blob: cb0fc0e1265c2e744b5163f16a7636deb9518655 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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, const Eo_Event *event 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_event_callback_priority_add(obj, 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];
   for (i = 0 ; i < len ; i++)
     {
        obj[i] = eo_add(SIMPLE_CLASS, NULL);

        for (j = 0 ; j < i ; j++)
          {
             eo_event_callback_priority_add(obj[i], 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_event_callback_call(obj[i], 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));
}