4
function assert(condition, message) {
6
print("Assertion failed ", message);
7
throw new Error(message || "Assertion failed");
11
if(typeof process !== 'undefined')
13
console.log('running from nodejs');
14
console.log('path', process.env.NODE_PATH);
17
assert(efl != null, "could not load efl node module");
21
print_error = function() {
22
if (process.argv.indexOf("--supress-errors") == -1)
23
console.error.apply(null, arguments);
25
print_info = function() {
26
if (process.argv.indexOf("--verbose") != -1)
27
console.info.apply(null, arguments);
29
exit = efl.Ecore.Mainloop.quit;
33
assert = function(test, message) { if (test !== true) throw message; };
34
print('running from libv8')
48
function start_test(test_name, test_func) {
49
print("[ RUN ] eina_js_suite: " + test_name);
50
var test_result = true;
54
suite_success = false;
56
print_error("Error: ", e, e.stack);
58
print("[ " + (test_result ? "PASS" : "FAIL") + " ] eina_js_suite: " + test_name);
62
suite_fail.push(test_name);
65
if (typeof process != "undefined")
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;
79
Benchmark_Object = suite.Benchmark_Object;
82
start_test("empty function", function(){
83
object = new Benchmark_Object(null);
85
for(i = 0; i != 10; i++)
90
time = process.hrtime();
91
for(i = 0; i != 20000; i++)
95
time = process.hrtime(time);
96
console.log('JS empty function %d', time[0]*1000000000 + time[1]);
100
start_test("onearg function", function(){
101
object = new Benchmark_Object(null);
102
for(i = 0; i != 10; i++)
107
time = process.hrtime();
108
for(i = 0; i != 20000; i++)
112
time = process.hrtime(time);
113
console.log('JS onearg function %d', time[0]*1000000000 + time[1]);
118
start_test("twoarg function", function(){
119
object = new Benchmark_Object(null);
120
for(i = 0; i != 10; i++)
125
time = process.hrtime();
126
for(i = 0; i != 20000; i++)
130
time = process.hrtime(time);
131
console.log('JS twoarg function %d', time[0]*1000000000 + time[1]);
136
start_test("tenarg function", function(){
137
object = new Benchmark_Object(null);
138
for(i = 0; i != 10; i++)
140
object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
143
time = process.hrtime();
144
for(i = 0; i != 20000; i++)
146
object.tenarg(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
148
time = process.hrtime(time);
149
console.log('JS tenarg function %d', time[0]*1000000000 + time[1]);
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++)
158
object.onecomplexarg(list);
161
time = process.hrtime();
162
for(i = 0; i != 20000; i++)
164
object.onecomplexarg(list);
166
time = process.hrtime(time);
167
console.log('JS onecomplexarg function %d', time[0]*1000000000 + time[1]);
168
benchmark_onecomplexarg();
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++)
176
object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
179
time = process.hrtime();
180
for(i = 0; i != 20000; i++)
182
object.tencomplexarg(list, list, list, list, list, list, list, list, list, list);
184
time = process.hrtime(time);
185
console.log('JS tencomplexarg function %d', time[0]*1000000000 + time[1]);
186
benchmark_tencomplexarg();
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]);
199
assert(false, "[ Test suite fail ]");
201
print ("[ Test execution with success ]");
202
print ("[ Total tests run: %s ]", suite_ok);