summaryrefslogtreecommitdiff
path: root/src/benchmarks/eo/eo_bench_eo_add.c
blob: 77f2eadb7f8d78cb374e1551996d9a8fa1f80727 (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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Eo.h"
#include "eo_bench.h"
#include "class_simple.h"

static void
bench_efl_add_linear(int request)
{
   int i;
   Eo **objs = calloc(request, sizeof(Eo *));
   for (i = 0 ; i < request ; i++)
      objs[i] = efl_add_ref(SIMPLE_CLASS, NULL);

   for (i = 0 ; i < request ; i++)
      efl_unref(objs[i]);
   free(objs);
}

static void
bench_efl_add_jump_by_2(int request)
{
   int i;
   Eo **objs = calloc(request, sizeof(Eo *));
   for (i = 0 ; i < request ; i++)
      objs[i] = efl_add_ref(SIMPLE_CLASS, NULL);

   for (i = 0 ; i < request ; i += 2)
      efl_unref(objs[i]);

   for (i = 0 ; i < request ; i += 2)
      objs[i] = efl_add_ref(SIMPLE_CLASS, NULL);

   for (i = 0 ; i < request ; i++)
      efl_unref(objs[i]);
   free(objs);
}

static void
bench_efl_add_shared_ownership(int request)
{
   int i;
   Eo **objs = calloc(request, sizeof(Eo *));
   Eo *p = efl_add_ref(SIMPLE_CLASS, NULL);
   for (i = 0; i < request; i++)
      objs[i] = efl_add_ref(SIMPLE_CLASS, p);
   efl_unref(p);
   for (i = 0; i < request; i++)
      efl_unref(objs[i]);
   free(objs);
}

static void
bench_efl_add_shared_ownership_alternative(int request)
{
   int i;
   Eo **objs = calloc(request, sizeof(Eo *));
   Eo *p = efl_add_ref(SIMPLE_CLASS, NULL);
   for (i = 0; i < request; i++)
      objs[i] = efl_add(SIMPLE_CLASS, p);
   for (i = 0; i < request; i++)
      efl_ref(objs[i]);
   for (i = 0; i < request; i++)
      efl_unref(objs[i]);
   efl_unref(p);
   free(objs);
}

void eo_bench_efl_add(Eina_Benchmark *bench)
{
   eina_benchmark_register(bench, "efl_add_linear",
         EINA_BENCHMARK(bench_efl_add_linear), _EO_BENCH_TIMES(1000, 10, 50000));
   eina_benchmark_register(bench, "efl_add_jump_by_2",
         EINA_BENCHMARK(bench_efl_add_jump_by_2), _EO_BENCH_TIMES(1000, 10, 50000));
   eina_benchmark_register(bench, "efl_add_shared_ownership",
         EINA_BENCHMARK(bench_efl_add_shared_ownership), _EO_BENCH_TIMES(1000, 10, 50000));
   eina_benchmark_register(bench, "efl_add_shared_ownership_alternative",
         EINA_BENCHMARK(bench_efl_add_shared_ownership_alternative), _EO_BENCH_TIMES(1000, 10, 50000));
}