Performance tests for C + + invoke Lua

Source: Internet
Author: User
Tags lua

游戏服务器经典的架构就是C++和Lua的结合,C++开发主体框架,Lua实现一些复杂的逻辑。我们都知道Lua是一种非常快的语言,但是到底有多块,我们测试下看看。C++调用Lua的性能测试,发现不对的地方望提出。

Experiment one: we use C + + to invoke Lua's function with more than 8 arguments, and this function does nothing. Through this experiment, we can simply test the time of using LUA virtual machines and passing 8+ parameters to the call stack and LUA fetching these parameters. However, there are various types of parameters, such as shaping, floating-point, and array. The LUA function of the experiment is relatively simple, as follows:

function test(x1,x2,x3,x4,x5,x6,x7,x8,x9)end

Experimental results: We call this function 1000 times the time required to about 35MS, that is, the time of the call at about 0.035MS

Experiment two: we use C + + to invoke the LUA function with one parameter, and the result of the experiment one can help us to find out the time and the parameters of using LUA virtual machine to enter and leave the stack.
Where the LUA function is very simple as follows:

function test(x1)end

Experimental results: We call this function 1000 times the time required to about 16ms, that is, the time of a call at about 0.016ms.

Experiment Three: We add LUA to the function of the experiment two to call C + + function, this function on the C + + side also do nothing, to test the LUA call C + + when the stack and the time of the stack.
The function is simple as follows:

function test(x1)    Chat(x1,x2,x3,x4,x5,x6,x7)end

Experimental results: We found that its use time is higher than (experiment two) about 15MS, estimated that the time to call a virtual machine is 14ms, the parameter time is estimated to be about 1ms

Experiment four: We have expanded its function parameters to 2 on the basis of experiment two, and we have observed that there is a slight change in its time.
The functions are as follows:

function test(x1,x2)end

Experimental results: We found that the time and experiment are similar, which may reflect the time of the stack is relatively fast, the application of the larger stack memory may occupy more time.

Experiment Five: We have expanded the parameters of the function to 3 on the basis of experiment two, and we find that the time has not changed significantly.
The functions are as follows:

function test(x1,x2,x3)end

Experimental results: Can reflect the time of the stack is relatively fast, the application of the larger stack memory may occupy more time.

Experiment Six: I extend the parameters of the function to 7, and we observe how the time changes.
The functions are as follows:

function test(x1,x2,x3,x4,x5,x6,x7)end

Experimental results: Found to go time and experiment five similar, perhaps can verify the time of the stack is relatively fast, the application of the larger stack memory may occupy more time.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Performance tests for C + + invoke Lua

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.