Hello i am currently trying to port a php-extension (native C) to a node.js native extensions.
i am using nan ->https://github.com/rvagg/nan - for api abstraction
i have the following node cpp code:
NAN_METHOD(Core::getInfo) {
NanScope();
int somevar=1;
Local<Object> return_obj = NanNew<Object>();
return_obj->Set(NanNew<v8::String>("int"),NanNew<v8::Integer>(somevar));
return_obj->Set(NanNew<v8::String>("version"),NanNew<v8::String>("teststr"));
NanReturnValue(return_obj);
}
and the following php-extension c code:
PHP_FUNCTION(core_get_info) {
int somevar;
if (array_init(return_value) == FAILURE) {
RETURN_FALSE;
}
add_assoc_long(return_value, "int", somevar);
add_assoc_string(return_value, "version", "teststr", 1);
}
when running the call to this function in 1000000 iterations the NODE variation is MUCH Slower.
test.php
for($x=0; $x<1000000; $x++) {
$i = core_get_info();
}
var_dump($i);
test.js
var x=0;
var i;
for(x=0; x<1000000; x++) {
i=core.getInfo();
}
console.log(i);
the factor seems to be about 170% slower in node than in php - has any one a tipp what i am doing fundamentally wrong in the node part.
edit: node version v0.11.14