summaryrefslogtreecommitdiff
path: root/src/tests/efl_js/benchmark_object_impl.cc
blob: 538c31b2ced93b0b7a5d4e81923ad3f562b7e7d6 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <Eo.h>
#include <Ecore.h>

#include <stdlib.h>

extern "C" {
#include "benchmark_object.eo.h"

void _benchmark_object_emptyarg(Eo*, void*)
{
}
void _benchmark_object_onearg(Eo*, void*, int)
{
}
void _benchmark_object_twoarg(Eo*, void*, int, int)
{
}
void _benchmark_object_tenarg(Eo*, void*, int, int, int, int, int, int, int, int, int, int)
{
}
void _benchmark_object_onecomplexarg(Eo*, void*, Eina_List*)
{
}
void _benchmark_object_tencomplexarg(Eo*, void*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*, Eina_List*)
{
}
  
#include "benchmark_object.eo.c"
}

#include "benchmark_object.eo.js.cc"

#ifdef HAVE_NODEJS
namespace {
using efl::eina::js::compatibility_return_type;
using efl::eina::js::compatibility_callback_info_type;
using efl::eina::js::compatibility_return;
using efl::eina::js::compatibility_new;

#define JS_BENCHMARK_ARGS0(v)
#define JS_BENCHMARK_ARGS1(v) v
#define JS_BENCHMARK_ARGS2(v) v,v
#define JS_BENCHMARK_ARGS10(v) v,v,v,v,v,v,v,v,v,v
#define JS_BENCHMARK_FUNC(name, number, v)                              \
  compatibility_return_type js_benchmark_object_##name##arg(compatibility_callback_info_type) \
  {                                                                     \
    Eina_Counter* counter = eina_counter_new("counter");                \
    Eo* object = eo_add(BENCHMARK_OBJECT_CLASS, NULL);                  \
    Eina_List* l = NULL;                                                \
    (void)l;                                                            \
    /* Warm */                                                          \
    for(int i = 0; i != 10; i++)                                        \
      {                                                                 \
        eo_do(object, benchmark_object_##name##arg(JS_BENCHMARK_ARGS##number(v))); \
      }                                                                 \
    /* Real loop */                                                     \
    eina_counter_start(counter);                                        \
    for(int i = 0; i != 20000; i++)                                     \
      {                                                                 \
        eo_do(object, benchmark_object_##name##arg(JS_BENCHMARK_ARGS##number(v))); \
      }                                                                 \
    eina_counter_stop(counter, 20000);                                  \
    fprintf(stderr, "%s", eina_counter_dump(counter));                  \
    eo_del(object);                                                     \
    return compatibility_return();                                      \
  }

JS_BENCHMARK_FUNC(empty, 0, 1)
JS_BENCHMARK_FUNC(one, 1, 1)
JS_BENCHMARK_FUNC(two, 2, 1)
JS_BENCHMARK_FUNC(ten, 10, 1)
JS_BENCHMARK_FUNC(onecomplex, 1, l)
JS_BENCHMARK_FUNC(tencomplex, 10, l)

  
void benchmark_object_module_init(v8::Handle<v8::Object> exports)
{
  fprintf(stderr, "test suite eolian_js_module_init\n"); fflush(stderr);
  try
    {
       eina_init();
       eo_init();
       register_benchmark_object(exports, v8::Isolate::GetCurrent());
#define JS_BENCHMARK_EXPORT(name)                                       \
       exports->Set(compatibility_new<v8::String>(nullptr, "benchmark_" #name "arg") \
                    , compatibility_new<v8::FunctionTemplate>(nullptr, &js_benchmark_object_##name##arg)->GetFunction());
       JS_BENCHMARK_EXPORT(empty)
       JS_BENCHMARK_EXPORT(one)
       JS_BENCHMARK_EXPORT(two)
       JS_BENCHMARK_EXPORT(ten)
       JS_BENCHMARK_EXPORT(onecomplex)
       JS_BENCHMARK_EXPORT(tencomplex)
    }
  catch(...)
    {
       std::cerr << "Error" << std::endl;
       std::abort();
    }
}

}

#include <eina_js_node.hh>

NODE_MODULE(benchmark_object, ::benchmark_object_module_init)
#endif