summaryrefslogtreecommitdiff
path: root/src/benchmarks/eo/eo_bench_callbacks.c
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-10-14 15:03:33 +0100
committerTom Hacohen <tom@stosb.com>2015-11-09 11:43:04 +0000
commit4bf0f6455d3b7df37c922fb011a0fa9c6cc12fe2 (patch)
tree34f36dd856ef578544a081c193e9f60804f04641 /src/benchmarks/eo/eo_bench_callbacks.c
parent862372ed2316d23e657f3562a4d5c77d05bd8849 (diff)
Eo benchmarks: Add basic callbacks benchmarks.
Diffstat (limited to 'src/benchmarks/eo/eo_bench_callbacks.c')
-rw-r--r--src/benchmarks/eo/eo_bench_callbacks.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/src/benchmarks/eo/eo_bench_callbacks.c b/src/benchmarks/eo/eo_bench_callbacks.c
new file mode 100644
index 0000000000..fde611eea1
--- /dev/null
+++ b/src/benchmarks/eo/eo_bench_callbacks.c
@@ -0,0 +1,85 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "eo_bench.h"
7#include "class_simple.h"
8
9static Eina_Bool
10_cb(void *data EINA_UNUSED, Eo *obj EINA_UNUSED, const Eo_Event_Description *desc EINA_UNUSED, void *event_info EINA_UNUSED)
11{
12 return EO_CALLBACK_CONTINUE;
13}
14
15
16static void
17bench_eo_callbacks_add(int request)
18{
19 int i;
20 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
21
22 for (i = 0 ; i < request ; i++)
23 {
24 eo_do(obj, eo_event_callback_priority_add(SIMPLE_FOO, (short) i, _cb, NULL));
25 }
26
27 eo_unref(obj);
28}
29
30static void
31bench_eo_callbacks_call(int request)
32{
33 /* Distribution of calls per amount of callbacks in an object as recorded by
34 running the genlist elementary_test test. */
35 const double distribution[] = {
36 0.2920468197,
37 0.2073086496,
38 0.217699456,
39 0.0207158285,
40 0.019707134,
41 0.0359433565,
42 0.0324896742,
43 0.0104299639,
44 0.028989003,
45 0.0082496801,
46 0.123214227,
47 0.0001331351,
48 0.0030730724
49 };
50
51 const int len = EINA_C_ARRAY_LENGTH(distribution);
52 int i, j;
53 Eo *obj[len] = { 0 };
54 for (i = 0 ; i < len ; i++)
55 {
56 obj[i] = eo_add(SIMPLE_CLASS, NULL);
57
58 for (j = 0 ; j < i ; j++)
59 {
60 eo_do(obj[i], eo_event_callback_priority_add(SIMPLE_FOO, (short) j, _cb, NULL));
61 }
62 }
63
64 for (i = 0 ; i < len ; i++)
65 {
66 for (j = 0 ; j < (int) (distribution[i] * request) ; j++)
67 {
68 /* Miss finding the callbacks on purpose, so we measure worst case scenario. */
69 eo_do(obj[i], eo_event_callback_call(SIMPLE_BAR, NULL));
70 }
71 }
72
73 for (i = 0 ; i < len ; i++)
74 {
75 eo_unref(obj[i]);
76 }
77}
78
79void eo_bench_callbacks(Eina_Benchmark *bench)
80{
81 eina_benchmark_register(bench, "add",
82 EINA_BENCHMARK(bench_eo_callbacks_add), _EO_BENCH_TIMES(1000, 10, 2000));
83 eina_benchmark_register(bench, "call",
84 EINA_BENCHMARK(bench_eo_callbacks_call), _EO_BENCH_TIMES(100000, 10, 500000));
85}