Skip to content

Instantly share code, notes, and snippets.

@DarkWiiPlayer
Last active April 30, 2022 13:54
Show Gist options
  • Save DarkWiiPlayer/98619d7a8e2dbbaca845de30e82dacd2 to your computer and use it in GitHub Desktop.
Save DarkWiiPlayer/98619d7a8e2dbbaca845de30e82dacd2 to your computer and use it in GitHub Desktop.
Lua benchmark: closures vs. coroutines
local times = 100000
local start = os.clock()
for i=1,times do
local closure = function()
print("test")
end
end
print(os.clock() - start)
local closure = function()
print("test")
end
local start = os.clock()
for i=1,times do
local co = coroutine.create(closure)
end
print(os.clock() - start)
$ lua5.1 -v
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
$ lua5.1 bench.lua
0.011985
0.066126
$ lua -v
Lua 5.3.4 Copyright (C) 1994-2017 Lua.org, PUC-Rio
$ lua bench.lua
0.003644
0.038367
$ luajit -v
LuaJIT 2.0.4 -- Copyright (C) 2005-2015 Mike Pall. http://luajit.org/
$ luajit bench.lua
0.009957
0.032188
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment