So I attempted to measure the memory overhead of a Stackless tasklet, with
'Recipe 286222' from ActiveState's Cookbook:
(on Linux 2.6.27-11-generic SMP x86_64)
def empty(): pass
b4 = memory()
print "before:", b4
t = stackless.tasklet(empty)()
after = memory()
print "after:", after
print "difference:", memory(b4)
Which yields:
difference: 4096.0
And a slightly modified version of Peter's test on my platform:
collectgarbage"collect"
local function F()
end
before = (collectgarbage"count" * 1024)
local C = coroutine.wrap(F)
after = (collectgarbage"count" * 1024)
print(after - before)
Yields:
1280
But perhaps a more reasonable question is, "how many licks does it take to
get to the center of a tootsie roll pop?"
On Fri, Apr 24, 2009 at 9:12 AM, Phoenix Sol <[email protected]>wrote:
> Very nice, thanks Peter!
>
>
> On Fri, Apr 24, 2009 at 9:08 AM, Peter Cawley <[email protected]> wrote:
>
>> A coroutine appears to cost around a kilobyte (20695 - 19601 = 1094
>> bytes):
>>
>> collectgarbage"collect"
>> print(collectgarbage"count" * 1024) --> 19559
>> local function F()
>> end
>> print(collectgarbage"count" * 1024) --> 19601
>> local C = coroutine.wrap(F)
>> print(collectgarbage"count" * 1024) --> 20695
>>
>> Test done on Win32/Vista, self-compiled Lua (using Visual Studio
>> 2008), source code executed all-at-once from a file rather than from
>> an interactive terminal.
>>
>> On Fri, Apr 24, 2009 at 4:52 PM, Phoenix Sol <[email protected]>
>> wrote:
>> > And is there a known overhead for a lua coro? (Maybe it would be more
>> fair
>> > to compare a tasklet to a 'Coco' coroutine... but still I wonder what
>> the
>> > overhead of wrapping a function with coroutine.wrap() is...)
>> >
>>
>
>
import os, stackless
_proc_status = '/proc/%d/status' % os.getpid()
_scale = {'kB': 1024.0, 'mB': 1024.0*1024.0,
'KB': 1024.0, 'MB': 1024.0*1024.0}
def _VmB(VmKey):
'''Private.
'''
global _proc_status, _scale
# get pseudo file /proc/<pid>/status
try:
t = open(_proc_status)
v = t.read()
t.close()
except:
return 0.0 # non-Linux?
# get VmKey line e.g. 'VmRSS: 9999 kB\n ...'
i = v.index(VmKey)
v = v[i:].split(None, 3) # whitespace
if len(v) < 3:
print "invalid format?"
return 0.0 # invalid format?
# convert Vm value to bytes
return float(v[1]) * _scale[v[2]]
def memory(since=0.0):
'''Return memory usage in bytes.
'''
return _VmB('VmSize:') - since
def resident(since=0.0):
'''Return resident memory usage in bytes.
'''
return _VmB('VmRSS:') - since
def stacksize(since=0.0):
'''Return stack size in bytes.
'''
return _VmB('VmStk:') - since
# measure the overhead of a tasklet
def empty(): pass
b4 = memory()
t = stackless.tasklet(empty)()
after = memory()
print "difference:", memory(b4)
collectgarbage"collect"
local function F()
end
before = (collectgarbage"count" * 1024)
local C = coroutine.wrap(F)
print((collectgarbage"count" * 1024) - before)
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless