Hi all,
I know that this matter has been covered several times, but in all previous posts, there are clear indication of interest about this matter. So, having done my own performance comparison I submit it to the community.
I understand that the scope of this comparison is very specific, but that comes from a particular need I have.
I currently build automation machines with a real time control done with a PC. Machine personalization is done with a series of programs currently written in Small.
These programs are normally compiled into byte code, and the byte code is then injected into the real time environment where a virtual machine does the real execution. The virtual machine exposes to the script several system function call to operate on the physical machine hardware (reading/setting input/outputs, moving axes, setting variables, ecc ...)
Due to the limitations of the Small language (lack of structures, no typing, no doubles, ...) I am investigating the possibility to switch to AngelScript.
Having solved most of the interface problems, now I have an AngelScript compiler and a real time virtual machine for execution running, so I am able to make some performance comparisons.
I started with a very simple script.
Here is the AS version:
int TestNum;
void main(void)
{
int count = 0;
for(int col = 0; col < 10000; col++)
{
count++;
ExtVar = count; // Line A: Makes one call to external environment
TestNum = count; // Line B: Only set a script variable
}
}
Here is the Small version:
new TestNum;
main()
{
new count = 0;
for(new col = 0; col < 10000; col++)
{
count++;
Set_ExtVar(count); // Line A: Makes one call to external environment
TestNum = count; // Line B: Only set a script variable
}
}
As you can see they are very similar, and basically they are made of single loop making one local variable increment and than an assignment.
Line A an B that you see in the code are alternatives. Only one of them were present during the evaluation.
This are the results in mS:
AS Small
Line A 4.37 1.85
Line B 3.05 1.07
Looks like AS is two to three times slower than Small.
Few final notes:
- The test was done on the same machine with similar load and same real time environment
- I didn't investigate the JIT, because I am not sure it can even work in the real time environment
- The external call is the same in both tests executing the same code, but it causes an additional 0.8mS in Small and 1.3mS is AS. Thus it is possible to conclude that the external function call is at least 0.5mS slower
- The jitter between test runs is in the order of than 0.05 in all cases
- The slight syntax difference between the two sources in line A is due to the fact that Small does not allow the definition of an external opAssing method, so en explicit function call is made. I believe that this result in a very similar byte code anyway.
- I am under the impression that AS virtual machine makes some allocation/deallocation during the run of the test, even if everything looks static (or at least allocated at the beginning). I tell this because if I let the test run repeatedly for one hour,, when I shout down the real time system the call to engine->Release takes as much as 5 minutes to complete. I am not able at the moment to tell exactly why.
Should you need further information or have me make further tests, just ask.
Regards.
Mau.
PS: Unfortunately these results forces us to stay with current solution, but I will keep a eye of further AS development, especially in the performance area.