Python `int` vs. Cython `cdef int`: 100x Speed Gap

Using Cython's `cdef int` for loop counters can yield speedups of 100x or more compared to Python's native arbitrary-precision `int`. This is because `cdef int` compiles directly to a fixed-size C integer, avoiding Python object overhead.

Sources

Open the full topic