码迷,mamicode.com
首页 > 其他好文 > 详细

xlua、tolua性能对比

时间:2020-05-18 16:20:11      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:性能   render   脚本   profile   cal   Fix   one   ror   ado   

  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 .. "\nreset transform.position\n" .. "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 .. "\ntransform.rotate\n" .. "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 .. "\nvector3.normalize\n" .. "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 .. "\nnew gameobject\n" .. "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 .. "\nreset component attributes\n" .. "test5/lua " .. (os.clock() - start))
end

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

 

xlua、tolua性能对比

标签:性能   render   脚本   profile   cal   Fix   one   ror   ado   

原文地址:https://www.cnblogs.com/hghhe/p/12910869.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!