Skip to content

Instantly share code, notes, and snippets.

@will-ca
Created March 26, 2020 06:04
Show Gist options
  • Save will-ca/ad1d1ed9bd9ec3ec9ce14553a7487690 to your computer and use it in GitHub Desktop.
Save will-ca/ad1d1ed9bd9ec3ec9ce14553a7487690 to your computer and use it in GitHub Desktop.
Quick test of the speed difference between `object` and `PyObject*` for frequently re-created `cdef` attributes.
import cython
from cpython cimport array
from cpython.ref cimport PyObject
cdef class addend_ptrwrapper:
cdef PyObject* obj
cdef bint nonzero
@cython.locals(s=cython.double, i=addend_ptrwrapper)
cpdef double add_ptrwrapped_floats(list seq)
@cython.locals(s=cython.int, i=addend_ptrwrapper)
cpdef int add_ptrwrapped_tuples(list seq)
cdef class addend_objwrapper:
cdef object obj
cdef bint nonzero
@cython.locals(s=cython.double, i=addend_objwrapper)
cpdef double add_objwrapped_floats(list seq)
@cython.locals(s=cython.int, i=addend_objwrapper)
cpdef int add_objwrapped_tuples(list seq)
@cython.locals(outseq=list, i=cython.int, w=addend_ptrwrapper)
cpdef list get_ptrtest_seq(list seq, bint getseq=*)
@cython.locals(outseq=list, i=cython.int, w=addend_objwrapper)
cpdef list get_objtest_seq(list seq, bint getseq=*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment