Speeding up text processing in Python (is hard)
If you’re doing text or string manipulation in Python, what do you do if your code is too slow? Assuming your algorithm is reasonably efficient, the next step is to try faster alternatives to Python: a compiled extension.
Unfortunately, this is harder than it seems. Some options don’t offer an easy path to optimizations, others are actually slower. To see this limitation in action, we’ll consider some alternatives:
- Pure Python, with the default Python interpreter.
- Cython.
- mypyc.
- Rust.
- Pure Python, with the PyPy interpreter.
We’ll also consider what can be done if these option don’t help.
Source: Speeding up text processing in Python (is hard), an article by Itamar Turner-Trauring.