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:
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):
prog:SetVertexShaderParam3f("eyePos", 1, 1, 1);
prog:SetVertexShaderParam4f("texMove", 1, 1, 1, 1);
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!
Zulfiqar Inayat Malik.