[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Performance of coroutine resume/yield
- From: Brian Hook <hook_l@...>
- Date: Sun, 29 Feb 2004 03:11:36 -0500
Are there any general performance guidelines on the relative cost of
coroutine.resume/yield? I have a situation where I may have several
thousand coroutines, many of which are effectively stubs (i.e. a
single coroutine.yield()). Obviously checking for this case is easy
enough that I could just avoid creating the coroutine and checking for
its existence:
for key, value in all_objects do
if value.coroutine then
coroutine.resume( value.coroutine )
end
end
But I have a related situation where the coroutine may need to be
fired every now and then, e.g. every 10 seconds. Is the cost of the
resume/yield pair high enough that the caller should check the
interval:
....
if value.coroutine then
if now - value.last_resume > value.update_interval then
coroutine.resume( value.coroutine )
end
end
....
or would I be okay just letting the object's update function check the
interval itself:
function object.update()
while true do
if now - self.last_resume < self.update_interval then
coroutine.yield( self.coroutine )
else
self.last_resume = now
-- do real work here
coroutine.yield( self.coroutine )
end
end
end
I couldn't find anything in the archives about the relative
performance of the coroutines.
Thanks,
Brian