Squirrel language execution speed

Source: Internet
Author: User

Iii. execution speed of Squirrel

It is worth noting that the execution speed of Squirrel is slow. Lua is always fast. Can Squirrel inherit and carry forward this feature? It is hard to say that the authors of Squirrel are not good at comparison, because Squirrel adds many new features. The authors say that the built-in Array of Squirrel must be faster than the Array simulated by Table in Lua (I don't think so, see my test results ).

I didn't specifically test the speed of Lua and Squirrel, but I read a Blog about "cloud Wind", saying that the Lua virtual machine is well optimized and executed based on "registers". I didn't study the Lua source code, squirrel's source code is crude. The code executing the bytecode does not seem to be as fine as Lua. It is estimated that Squirrel's execution speed will be slower than Lua in the same case.

Although Squirrel may be slower than Lua, it is still a relatively fast scripting language. After all, its core idea is derived from Lua. In my 1.5G
On Laptop, an array is created and traversed at a speed of about 1/4 of C ++. The test code is as follows:

C ++:

Std: vector <int>
Arr;

For (int I = 0; I <1000; I ++) arr. push_back (I * 13 );

Int
Total = 0;

For (int
J = 0; j <1000; j ++) total + = arr [j];

 

Squirrel Array:

Local arr = [];

For (local I = 0; I <1000; I ++) arr. append (I * 13 );

Local total = 0;

For (local j = 0; j <1000; j ++) total + = arr [j];

 

Squirrel Table:

Local
Tb = {};

For (local I = 0; I <1000; I ++) tb [I] <-(I * 13 );

Local total2 = 0;

For (local j = 0; j <1000; j ++) total2 + = tb [j];

Tm. endClock ();

 

I used the TSC register inside the CPU for direct running time measurement (it should be one of the most precise running time measurement methods at present, 1.5 M CPU clock pulse for one millisecond), run the previous code, C ++ uses a 280 k cpu clock pulse, Squirrel Array uses a 1110 k cpu clock pulse, and Squirrel Table uses a 903 k cpu clock pulse.

This test is very interesting. Squirrel's Table is actually a little faster than Array, which is totally surprising to me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.