New issue 2887: CFFI call with bool is much slower than int
https://bitbucket.org/pypy/pypy/issues/2887/cffi-call-with-bool-is-much-slower-than

Tinho Lee:

Here is a simple test case, where *x* is a pre-compiled cffi module, and 
*empty* is just a empty c function with signature *void empty(bool, bool, 
bool);*.

test_a costs about 0.22s, while test_b 0.17s. It seems passing python bool to c 
bool_t is slower than passing python int. 

```
#!python

def test_a():
        for n in xrange(10000000):
                x.lib.empty(True, True, True)

def test_b():
        for n in xrange(10000000):
                x.lib.empty(1, 1, 1)

```

I have read the code *convert_from_object* of *W_CTypePrimitiveBool* in 
ctypeprim.py, which calls *misc.as_unsigned_long* for conversion. 

There is a shortcut for *W_IntObject* inside the method *as_unsigned_long*, 
however, *W_BoolObject* would be treated as big int for a much slower 
conversion. It seems some optimization could help to improve the performance of 
passing python bool.


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to