I posted about f2pypy my mini-project to make a new backend to f2py which generates a ctypes-based extension module for Python. The goal is to see if that is a viable path for PyPy support of the existing shared libraries already wrapped by f2py. I think it is.
Feel free to comment!
Wednesday, November 9, 2011
Subscribe to:
Post Comments (Atom)

1 comments:
note that PyPy has also another, (faster) way to call C function: the _ffi module, which ctypes is built on top of.
On my machine:
viper tmp $ cat x.py
import ctypes
m = ctypes.cdll.LoadLibrary("libm.so")
cos = m.cos
cos.argtypes = [ctypes.c_double]
cos.restype = ctypes.c_double
viper tmp $ cat y.py
import _ffi
m = _ffi.CDLL('libm.so')
cos = m.getfunc('cos', [_ffi.types.double], _ffi.types.double)
viper tmp $ pypy-c -m timeit "from x import cos" "cos(0)"
10000000 loops, best of 3: 0.0393 usec per loop
viper tmp $ pypy-c -m timeit "from y import cos" "cos(0)"
100000000 loops, best of 3: 0.0148 usec per loop
viper tmp $ pypy-c -m timeit "from math import cos" "cos(0)"
100000000 loops, best of 3: 0.0076 usec per loop
still not as good as math.cos, but that's because _ffi calls always release the GIL, while math.cos doesn't.
Post a Comment