efl

Форк
0
/
benchmark_js_suite.js 
205 строк · 5.2 Кб
1
#!/usr/bin/env node
2

3
// Preamble
4
function assert(condition, message) {
5
  if (!condition) {
6
      print("Assertion failed ", message);
7
      throw new Error(message || "Assertion failed");
8
  }
9
}
10

11
if(typeof process !== 'undefined')
12
{
13
    console.log('running from nodejs');
14
    console.log('path', process.env.NODE_PATH);
15

16
    efl = require('efl');
17
    assert(efl != null, "could not load efl node module");
18

19
    // Setup output aliases
20
    print = console.log;
21
    print_error = function() {
22
        if (process.argv.indexOf("--supress-errors") == -1)
23
            console.error.apply(null, arguments);
24
    };
25
    print_info = function() {
26
        if (process.argv.indexOf("--verbose") != -1)
27
            console.info.apply(null, arguments);
28
    };
29
    exit = efl.Ecore.Mainloop.quit;
30
}
31
else
32
{
33
    assert = function(test, message) { if (test !== true) throw message; };
34
    print('running from libv8')
35
    //FIXME Add levels to v8 tests
36
    print_error = print
37
    print_info = print
38
    exit = function() {}
39
}
40

41
// Global flag for suite success //
42
suite_success = true;
43
// Global test summary
44
suite_ok = 0;
45
suite_fail = []; // Will store the name of the failures
46

47
// Basic test function //
48
function start_test(test_name, test_func) {
49
  print("[ RUN         ]  eina_js_suite: " + test_name);
50
  var test_result = true;
51
  try {
52
    test_func();
53
  } catch (e) {
54
    suite_success = false;
55
    test_result = false;
56
    print_error("Error: ", e, e.stack);
57
  }
58
  print("[        " + (test_result ? "PASS" : "FAIL") + " ]  eina_js_suite: " + test_name);
59
  if (test_result)
60
    suite_ok += 1;
61
  else
62
    suite_fail.push(test_name);
63
}
64
// end Preamble
65
if (typeof process != "undefined")
66
{
67
    benchmark = require('benchmark_object');
68
    assert(benchmark != null, "could not load benchmark_object.node");
69
    Benchmark_Object = benchmark.BenchmarkObject;
70
    benchmark_emptyarg = benchmark.benchmark_emptyarg;
71
    benchmark_onearg = benchmark.benchmark_onearg;
72
    benchmark_twoarg = benchmark.benchmark_twoarg;
73
    benchmark_tenarg = benchmark.benchmark_tenarg;
74
    benchmark_onecomplexarg = benchmark.benchmark_onecomplexarg;
75
    benchmark_tencomplexarg = benchmark.benchmark_tencomplexarg;
76
}
77
else
78
{
79
    Benchmark_Object = suite.Benchmark_Object;
80
}
81

82
start_test("empty function", function(){
83
    object = new Benchmark_Object(null);
84

85
    for(i = 0; i != 10; i++)
86
    {
87
        object.emptyarg();
88
    }
89
    
90
    time = process.hrtime();
91
    for(i = 0; i != 20000; i++)
92
    {
93
        object.emptyarg();
94
    }
95
    time = process.hrtime(time);
96
    console.log('JS empty function %d', time[0]*1000000000 + time[1]);
97
    benchmark_emptyarg();    
98
});
99

100
start_test("onearg function", function(){
101
    object = new Benchmark_Object(null);
102
    for(i = 0; i != 10; i++)
103
    {
104
        object.onearg(1);
105
    }
106

107
    time = process.hrtime();
108
    for(i = 0; i != 20000; i++)
109
    {
110
        object.onearg(1);
111
    }
112
    time = process.hrtime(time);
113
    console.log('JS onearg function %d', time[0]*1000000000 + time[1]);
114

115
    benchmark_onearg();    
116
});
117

118
start_test("twoarg function", function(){
119
    object = new Benchmark_Object(null);
120
    for(i = 0; i != 10; i++)
121
    {
122
        object.twoarg(1, 2);
123
    }
124

125
    time = process.hrtime();
126
    for(i = 0; i != 20000; i++)
127
    {
128
        object.twoarg(1, 2);
129
    }
130
    time = process.hrtime(time);
131
    console.log('JS twoarg function %d', time[0]*1000000000 + time[1]);
132

133
    benchmark_twoarg();    
134
});
135

136
start_test("tenarg function", function(){
137
    object = new Benchmark_Object(null);
138
    for(i = 0; i != 10; i++)
139
    {
140
        object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
141
    }
142

143
    time = process.hrtime();
144
    for(i = 0; i != 20000; i++)
145
    {
146
        object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
147
    }
148
    time = process.hrtime(time);
149
    console.log('JS tenarg function %d', time[0]*1000000000 + time[1]);
150
    benchmark_tenarg();    
151
});
152

153
start_test("onecomplexarg function", function(){
154
    object = new Benchmark_Object(null);
155
    list = new efl.List('int')
156
    for(i = 0; i != 10; i++)
157
    {
158
        object.onecomplexarg(list);
159
    }
160

161
    time = process.hrtime();
162
    for(i = 0; i != 20000; i++)
163
    {
164
        object.onecomplexarg(list);
165
    }
166
    time = process.hrtime(time);
167
    console.log('JS onecomplexarg function %d', time[0]*1000000000 + time[1]);
168
    benchmark_onecomplexarg();    
169
});
170

171
start_test("tencomplexarg function", function(){
172
    object = new Benchmark_Object(null);
173
    list = new efl.List('int')
174
    for(i = 0; i != 10; i++)
175
    {
176
        object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
177
    }
178

179
    time = process.hrtime();
180
    for(i = 0; i != 20000; i++)
181
    {
182
        object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
183
    }
184
    time = process.hrtime(time);
185
    console.log('JS tencomplexarg function %d', time[0]*1000000000 + time[1]);
186
    benchmark_tencomplexarg();    
187
});
188

189
// footer
190

191
if (!suite_success) {
192
  print ("[ Total tests run: %s ]", suite_ok + suite_fail.length);
193
  print ("[ Total successful: %s ]", suite_ok);
194
  print ("[ Total failures: %s ]", suite_fail.length);
195
  print ("[ Tests failed: ]");
196
  for (var i = 0; i < suite_fail.length; i++) {
197
    print ("[    %s]", suite_fail[i]);
198
  };
199
  assert(false, "[ Test suite fail ]");
200
} else {
201
  print ("[ Test execution with success ]");
202
  print ("[ Total tests run: %s ]", suite_ok);
203
}
204

205
exit();
206

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.