2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Lua] rawset は別に速くなかった

Posted at

table.insert

bench1.cmd
::rem:: --[[ vim:set ft=lua:
@lua "%~f0" %* & exit /b
]]--
t = {}
for i=1,100000 do
    table.insert(t,"x")
end
print(os.clock())
$ bench1
0.018

普通にテーブルアクセス

bench2.cmd
::rem:: --[[ vim:set ft=lua:
@lua "%~f0" %* & exit /b
]]--
t = {}
for i=1,100000 do
    t[i] = "x"
end
print(os.clock())
$ bench2
0.006

rawset

bench3.cmd
::rem:: --[[ vim:set ft=lua:
@lua "%~f0" %* & exit /b
]]--
t = {}
for i=1,100000 do
    rawset(t,i,"x")
end
print(os.clock())
$ bench3
0.015

結論

  • 関数コールが入るとやはり遅い
  • 人間素直に生きよう
  • そんなに気にするんだったら、LuaJIT 使えば?
2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?