Lua is slower than Squirrel, strange

Source: Internet
Author: User

In the office, with the Lua environment, I decided to give a try on the Lua running speed. The measurement method is the same as Squirrel, and the C code reading the TSC register is encapsulated into a method, in Lua and Squirrel, I was surprised by the test results. Lua is actually slower Than Squirrel.

 

Lua Table:

Tb = {};

I = 0;

While (I <1000)

Do

Tb [I] = I * 13

I = I + 1;

End

 

Total = 0;

I = 0;

While (I <1000)

Do

Total = total + tb [I];

I = I + 1;

End

 

This program is similar to the Squirrel test program. Lua spends 20% K of CPU pulse on executing this code, and Squirrel is almost faster than Lua. I don't want to come to the conclusion that Squirrel is faster than Lua. Does Lua scan, analyze, and execute code? Squirrel has actually pre-compiled before executing the code, and the script file has become the mainland bytecode stored in Squirrel Virtual Machine. If Lua does not adopt and compile the technology, it is understandable that it lags behind Squirrel.

I did not develop games. I only know the basic usage of Lua. If you have a Lua master, you can help me check whether the Lua virtual machine has a pre-compilation process. If not, lua can fully pre-compile like Squirrel to improve execution speed.

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.