js调用cs慢。希望能和xlua一致
fghj0810 opened this issue · 2 comments
fghj0810 commented
CSharp函数实现是空的
function Test10(trans)
for i = 1, 2000000 do
CS.UserClass.TestFunc(1, "123", 0.5)
end
end
function test10(): void {
for (let i = 0; i < 2000000; i++)
{
UserClass.TestFunc(1, "123", 0.5);
}
}
lua耗时254ms
js耗时336ms
function Test10(trans)
local go = GameObject("t")
local transform = go.transform
for i = 1, 2000000 do
CS.UserClass.TestFunc2(1, "123", transform)
end
GameObject.Destroy(go)
end
function test10(): void {
let go = new GameObject("t");
let transform = go.transform;
for (let i = 0; i < 2000000; i++)
{
UserClass.TestFunc2(1, "123", transform);
}
GameObject.Destroy(go);
}
lua耗时440ms
js耗时904ms
测试平台windows x64
kenkinky commented
import TestFunc2 = CS.UserClass.TestFunc2, 有帮助吗?
chexiongsheng commented
window测试其实意义不大。应该用手机测试比较符合真实情况。
其次一致是不可能的,比如你这用到的字符串。在获取lua虚拟机的字符串只是简单返回个指针,而v8需要你给一段buff(可能还得动态new,因为你不知道得多长),由v8拷贝到你提供的buff里头。中间还可能转码(UTF16转UTF8)。