Hi,

There seems to be a lot of overhead when passing a large string (23 Meg) 
to C compiled RPython code.  For example, this code:

def small(text):
    return 3

t = Translation(small)
t.annotate()
t.rtype()
f3 = t.compile_c()

st = time.time()
z = f3(xml)
print time.time() - st

Whereas parsing the 16,000 XML elements using a regular expression only 
took 22 msec.  Even reading the text file inside the compiled RPython is 
faster than passing it.

Here's the code from rstr.py that (seems to be) doing the conversion. 
Any idea how I'd put timing code in there to see what's taking all the 
time?  Any idea how to speed it up?

class __extend__(pairtype(PyObjRepr, AbstractStringRepr)):
     def convert_from_to((r_from, r_to), v, llops):
         v_len = llops.gencapicall('PyString_Size', [v], resulttype=Signed)
         cstr = inputconst(Void, STR)
         v_result = llops.genop('malloc_varsize', [cstr, v_len],
                                resulttype=Ptr(STR))
         cchars = inputconst(Void, "chars")
         v_chars = llops.genop('getsubstruct', [v_result, cchars],
                               resulttype=Ptr(STR.chars))
         llops.gencapicall('PyString_ToLLCharArray', [v, v_chars])
         string_repr = llops.rtyper.type_system.rstr.string_repr
         v_result = llops.convertvar(v_result, string_repr, r_to)
         return v_result

Best,
Martin


_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev

Reply via email to