[pypy-dev] very slow ctypes callbacks

Arman Bostani a at bostani.us
Mon Dec 19 05:27:08 CET 2011


Hi all,

I believe this problem has been brought to your attention before. But,
perhaps it something that can be added to the bug list.

I'm using a proprietary Windows library which unfortunately uses callbacks
a lot. I've attached a simple test case. Under pypy 1.7, this runs about 8
times slower than CPython 2.7.

Best, -arman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20111218/f1dd284d/attachment.html>
-------------- next part --------------
from ctypes import *
import timeit

def py_cmp_func(a, b):
    return a[0] - b[0]

CMPFUNC   = CFUNCTYPE(c_int, POINTER(c_int), POINTER(c_int))
cmp_func  = CMPFUNC(py_cmp_func)
int_size  = sizeof(c_int)
LEN       = 5
IntArray5 = c_int * LEN
ia        = IntArray5(5, 1, 7, 33, 99)
qsort     = cdll.msvcrt.qsort

def f():
    qsort(ia, LEN, int_size, cmp_func)

print timeit.repeat("f()", "from __main__ import f", number=100000)


More information about the pypy-dev mailing list