xlua、tolua性能对比

  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()
复制代码

 

posted @   hghhe  阅读(2686)  评论(1编辑  收藏  举报
编辑推荐:
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· 2 本地部署DeepSeek模型构建本地知识库+联网搜索详细步骤
点击右上角即可分享
微信分享提示