Last active
April 30, 2022 13:54
-
-
Save DarkWiiPlayer/98619d7a8e2dbbaca845de30e82dacd2 to your computer and use it in GitHub Desktop.
Lua benchmark: closures vs. coroutines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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