Skip to content

Instantly share code, notes, and snippets.

@hnakamur
Created August 28, 2012 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnakamur/3505055 to your computer and use it in GitHub Desktop.
Save hnakamur/3505055 to your computer and use it in GitHub Desktop.
1M coroutine creation in luvit
local coroutine = require('coroutine')
local uv = require('uv_native')
local n = tonumber(process.argv[1])
print("n=" .. n)
local c = {}
local startTime = uv.hrtime()
for i = 1, n do
c[i] = coroutine.create(function()
print("hi")
end)
end
local endTime = uv.hrtime()
print("elapsed=" .. (endTime - startTime))
--[[
Results on Macbook Pro Retina 2012
CPU: Intel Core i7 2.6 GHz
Mem: 16GB 1600 MHz DDR3
bash-3.2$ time luvit coroutine_time.lua 50000
n=50000
elapsed=25.578958004713
real 0m0.045s
user 0m0.026s
sys 0m0.015s
bash-3.2$ time luvit coroutine_time.lua 200000
n=200000
elapsed=97.996458977461
real 0m0.120s
user 0m0.074s
sys 0m0.045s
bash-3.2$ time luvit coroutine_time.lua 300000
n=300000
elapsed=149.57677599788
real 0m0.176s
user 0m0.110s
sys 0m0.064s
bash-3.2$ time luvit coroutine_time.lua 400000
n=400000
elapsed=219.89208099246
real 0m0.250s
user 0m0.170s
sys 0m0.075s
bash-3.2$ time luvit coroutine_time.lua 500000
n=500000
elapsed=258.14057099819
real 0m0.299s
user 0m0.196s
sys 0m0.088s
bash-3.2$ time luvit coroutine_time.lua 1000000
n=1000000
elapsed=597.65801200271
real 0m0.651s
user 0m0.469s
sys 0m0.178s
--]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment