xluatolua性能对比

Posted hghhe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了xluatolua性能对比相关的知识,希望对你有一定的参考价值。

  Unity版本:2018.4.3,mac版

  测试平台:都选择android平台, 编辑器下运行

  xlua版本:2.1.14

  tolua版本:Aug 9, 2019发布版本

  测试方法:相同的lua代码,每个测试用例取稳定值

  测试结果:技术图片

  通过上图发现,xlua全面占优啊。附上测试的lua脚本:

if not UnityEngine.GameObject then
error("Click Make/All to generate lua wrap file")
end

local Vector3 = UnityEngine.Vector3
local GameObject = UnityEngine.GameObject
local Profiler = UnityEngine.Profiler
local Time = UnityEngine.Time
local Matrix4x4 = UnityEngine.Matrix4x4
local Texture2D = UnityEngine.Texture2D
local Quaternion = UnityEngine.Quaternion
local SkinnedMeshRenderer = UnityEngine.SkinnedMeshRenderer

function main()
print(jit and "jit on" or "jit off, pls run test with luajit")
end

local cube = GameObject("Script cube")
local prefix = jit and "jit on" or "jit off"

function test1()
local transform = cube.transform
local start = os.clock()
for i=1,200000 do
transform.position=transform.position
end
print(prefix .. "
reset transform.position
" .. "test1/lua " .. (os.clock() - start))
end

function test2()
local transform=cube.transform
local start = os.clock()
for i=1,200000 do
transform:Rotate(Vector3.up, 90)
end
print(prefix .. "
transform.rotate
" .. "test2/lua " .. (os.clock() - start))
end

function test3()
local start = os.clock()
for i=1,2000000 do 
local v = Vector3(i,i,i)
Vector3.Normalize(v)
end
print(prefix .. "
vector3.normalize
" .. "test3/lua " .. (os.clock() - start))
end

function test4()
local t = cube.transform
local v = Vector3.one
local start = os.clock()
for i=1,200000 do
local v = GameObject()    
end
print(prefix .. "
new gameobject
" .. "test4/lua " .. (os.clock() - start))
end


function test5()
local v = cube.transform.position
local start = os.clock()
for i=1,20000 do
local v = GameObject()
v:AddComponent(typeof(SkinnedMeshRenderer))
local c=v:GetComponent(typeof(SkinnedMeshRenderer))
c.receiveShadows=false
end
print(prefix .. "
reset component attributes
" .. "test5/lua " .. (os.clock() - start))
end

main()
test1()
test2()
test3()
test4()
test5()

 

以上是关于xluatolua性能对比的主要内容,如果未能解决你的问题,请参考以下文章

JavaWeb - JSONProtobufThriftMessagePack 对比和开发指南

自旋锁,互斥锁,原子变量性能对比

Pytorch优化器全总结常用优化器性能对比 含代码

JDBC插入优化性能对比

java StringString.concat和StringBuilder性能对比

SCI期刊写作必备:代码|手把手绘制目标检测领域YOLO论文常见的性能对比折线图,一键生成YOLOv7等主流论文同款图表,包含多种不同功能风格对比图表