lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

 

I have been using LUA for quite some time now, but never took the opportunity to benchmark it against other languages like C/C++, until now. Recently I started development on a very unique and extensive material system with really good scripting support, such that the user would not have to change even a single line of code in the engine/game to make a new material. The game and engine would expose certain functionality to the scripts and the scripts will use that functionality to achieve a certain purpose (along with shaders etc.).

 

For this purpose I decided to profile LUA against raw C++ code. Since I was designing a material system, I decided to use the following test scenarios:

 

  • Shader binding/unbinding and multiple parameters being passed to shaders.
  • Math function testing. For that I chose trigonometric functions like sin and cos.
  • Function calling. Both C++ function calling from LUA and LUA calling LUA functions.

 

I stress test the scenarios multiple times e.g. 1000, 5000, 10000, 100000 etc. each time coming up with the same result. LUA code execution is very fast, but initial LUA loading is slow. Consider the following code as an example (LUA code):

 

function Test()

 

prog:Bind();

 

prog:SetVertexShaderParam3f("eyePos", 1, 1, 1);

prog:SetVertexShaderParam4f("texMove", 1, 1, 1, 1);

prog:SetSampler("frameBuffer", 6);

prog:SetSampler("normalMap", 1);

prog:SetSampler("distortionMap", 2);

prog:SetFragmentShaderParam1f("screenWidth", 800);

prog:SetFragmentShaderParam1f("screenHeight", 600);

prog:SetFragmentShaderParam1f("etaRatio", 0.1);

 

prog:Unbind();

 

end

 

Test();

 

Calling this script 10,000 times takes apporx 906ms. However if I comment out the last line, then the script will actually be doing nothing, but it still takes up 828ms to execute the same number of times as before!!! This has led me to believe that the actual code execution is pretty fast, whilst the setup (parsing, although I heard that theoretically LUA will parse this file/string only once!) is taking all the time. Can someone help me get rid of this lag so that I can get on making a powerful material system. Lua_dofile is horribly slower so I resided to lua_dostring and lua_dobuffer. I have also tried pre-compiling the code using luac.exe but with only a slight performance gain.

 

Any help in this regard shall be highly appreciated!

 

Regards,

Zulfiqar Inayat Malik.