Conversion of Python sequences to C++ vectors currently looks like:
cdef vector[cydriver.CUatomicOperation] cyoperations = [int(pyoperations) for pyoperations in (operations)]
This has a number of suboptimal things:
- It creates a temporary Python list (which may be
realloc'd multiple times as it grows) that is totally unnecessary.
- List comprehensions are significantly slower than for loops in Cython, since the former requires making multiple Python-level calls to an iterator object.
Instead, we know the length of the sequence in advance, so we can resize or pre-allocate the vector of the correct size, and then fill it with a for loop.
Conversion of Python sequences to C++ vectors currently looks like:
This has a number of suboptimal things:
realloc'dmultiple times as it grows) that is totally unnecessary.Instead, we know the length of the sequence in advance, so we can
resizeor pre-allocate the vector of the correct size, and then fill it with a for loop.