Sign in to follow this  

Contex & Function Calls

This topic is 4258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Should I call ex. "contex->Prepare(functionID);" every time I wish to call a function? I have speed tested it and it is three-times slower then in LUA if I have to. AngelScript
int r = 0;

// Find the function id for the function we want to execute.
int functionID = engine->GetFunctionIDByDecl(0, "float testFunc(float)");
if( functionID < 0 )
{
 cout << "Test2() - The function 'float testFunc(float)' was not found." << endl;
 contex->Release();
 return -1;
}
		
timeOut = g_Timer.get() + 5.0;
		
//Operation speed test
OST = g_Timer.get();

int accum = 0;

r = contex->Prepare(functionID);
if( r < 0 ) 
{
 cout << "Test2() - Failed to prepare the context." << endl;
 return -1;
}

for (unsigned int i = 0; i < sz; i++)
{
 contex->SetArgFloat(0, 2.55);

 contex->Execute();
 accum += contex->GetReturnFloat();
}

//Operation speed test
OST = g_Timer.get() - OST;
...
LUA

//Operation speed test
OST = g_Timer.get();

//g_scriptMgr.openFunc("testFunc");
//g_scriptMgr.addNumber(2.55);

int accum = 0;

for (unsigned int i = 0; i < sz; i++)
{
 lua_pushstring(m_luaVM, "testFunc"); 
 lua_gettable(m_luaVM, LUA_GLOBALSINDEX); 
 lua_pushnumber(m_luaVM, 2.55);
 lua_call(m_luaVM, 1, 1);
 const double ret = lua_tonumber(m_luaVM, -1);
 lua_pop(m_luaVM, 1);

 accum += ret;
}

//Operation speed test
OST = g_Timer.get() - OST;
...
[Edited by - ZeroSigma on April 19, 2006 5:34:55 AM]

Share this post


Link to post
Share on other sites
I remember hearing at one point that if execute returns asEXECUTION_FINISHED, that the context was ready to run that same function again immediatly; but I am probably wrong and am not doing it that way myself anyway.

And your logic is flawed. It might take Angelscript longer than LUA to actually get executing; I have nothing to dispute that; but in any sort of non-trivial test Angelscript has been shown to execute faster. Furthermore, if your sole criteria for choosing a language is speed, don't use any scripting language, use C++ instead. Your post was rather accusatory, as if you were suggesting Angelscript advocates had been lieing through their teeth about it's performance in an attempt to make you choose Angelscript over LUA. I don't think that attitude will be appreciated here.

Share this post


Link to post
Share on other sites
Calm down, Deyja! [smile]

I actually appreciate ZeroSigma's post. As it gives me some hints as to where I need to spend time optimizing the code.

I was already aware that the Prepare() method is a bottle neck in situations where many tiny script functions must be called, I just didn't know how big that bottleneck was. I'll definitely put som effort into making it less heavy.

Even though you must call Prepare() every time you start a new function call, you can make it faster by calling Prepare(-1) if the function happens to be the same as the last call.

By the way, what does the scripted testFunc() look like?

Regards,
Andreas

Share this post


Link to post
Share on other sites
Thanks and sorry WitchLord if I sound antagonistic towards the great work you are doing I apologise to you.
Anyway here are the scripts that are executed:

AngelScript

float testFunc(float inPara)
{
return inPara + inPara;
}


LUA

function testFunc(_in)
return _in + _in
end


Let me put it into contex for you: I have entities in a game that fire events and respond to events by executing scripted functions. A lot of entities = a lot of function calls.

Speed is a very importent criteria to me, I'm using Visual C++ as my development base and need a good scripting language like Angelscript or LUA to be my data -driven-design actuator. RPGs/RTSs and Scripting mixes well and a lot.

[Edited by - ZeroSigma on April 19, 2006 5:04:13 AM]

Share this post


Link to post
Share on other sites
Don't worry, no offense taken. [smile]

I'm sure there are a lot that can be done to speed up the Prepare() method. The first and most obvious thing that I'll do is to avoid dynamic allocation of the stack memory for each call, and I can also precalculate a lot of the information determined at the moment of that call. I'll try to do this until the next major release, though I can't promise anything as I have a lot of other important things to do for the next release as well.

Share this post


Link to post
Share on other sites

This topic is 4258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this