var raycast_count ;
var raytracer = new kraytracer() ;
raytracer.oncastray = function( x, y )
{
++ raycast_count ;
return true ;
}
// this loop takes about 0.03 seconds to run
raycast_count = 0 ;
for ( var j = 0 ; j < 1980 ; ++j )
for ( var i = 0 ; i < 1440 ; ++ i )
raytracer.oncastray( i, j ) ;
// raytracer.begin() is C++ function that performs the same loop above.
// It takes 13 seconds though!
raycast_count = 0 ;
raytracer.begin() ;
void v8raytracer::begin( const FunctionCallbackInfo<Value> & info )
{
...
...
Local<Value> oncastray = info.This()->Get( String::NewFromUtf8( isolate, "oncastray" ) ) ;
Handle<Value> parameters[ 2 ] ;
Local<Value> rcv = info.This() ;
if ( oncastray->IsFunction() )
{
Local<Function> oncastray_fn = Handle<Function>::Cast( oncastray ) ;
for ( int j = 0 ; j < 1980 ; ++j )
for ( int i = 0 ; i < 1440 ; ++i )
{
parameters[ 0 ] = Integer::New( isolate, x ) ;
parameters[ 1 ] = Integer::New( isolate, y ) ;
oncastray_fn->Call( rcv, 2, parameters ) ;
}
}
...
...
}
{
HandleScope scope( isolate ) ;
parameters[ 0 ] = Integer::New( isolate, x ) ;
parameters[ 1 ] = Integer::New( isolate, y ) ;
return oncastray_fn->Call( rcv, 2, parameters )->ToBoolean()->Value() ;
}
The call is still slow but it is much better now. I will take your advice and learn how to use typed Arrays. Many thanks for this tip.
b e n