I'm trying to demonstrate to our group the virtues of Cython for enhancing Python performance. I have shown several benchmarks, all that attain speed up by just:
- Compiling the existing Python code.
- Using cdef to static type variables, particular in inner loops.
However, much of our code does string manipulation, and I have not been able to come up with good examples of optimizing code by typing Python strings.
An example I've tried is:
cdef str a
cdef int i,j
for j in range(1000000):
a = str([chr(i) for i in range(127)])
but typing 'a' as a string actually makes the code run slower. I've read the documentation on 'Unicode and passing strings', but am confused about how it applies in the case I've shown. We don't use Unicode--everything is pure ASCII. We're using Python 2.7.2
Any advice is appreciated.