On Saturday, May 11, 2013 8:28:19 AM UTC+2, Geert Jansen wrote:
Hi,
I have a C function for framing JSON objects from a stream. This function is written in C for speed. Originally this function was exposed via a python extension module. I have been doing an experiment where I exposed this function via CFFI. My goal is to have one high performance function that I can share between CPython and PyPy. The results are below:
Just a thought:
def cffi_split(buf, offset=0, state=0):
c_buf = ffi.new('char[]', buf)
c_offset = ffi.new('int *', offset)
c_state = ffi.new('int *', state)
ret = lib.split_json(c_buf, len(buf), c_offset, c_state)
return (ret, c_offset[0], c_state[0])
every invocation of this function allocates three buffers, while three
buffers from the previous run are freed. So you're maybe comparing apples
with pears - all this extra work isn't done elsewhere. Try allocating the
buffers once and only loop over the lib.split_json call. If the call to
lib.split_json takes little time, the allocation/deallocation might
contribute a lot to the total processing time.
Kay