pythoncython

Performance comparison Static Typing Python 3.6+ vs Cython


Recently Python 3.6 added static typing as a way to enforce certain types. This same functionality I used to get it from Cython, obtaining highly optimized functions when compared to vanilla Python.

My question then is: Will we also get substantial a performance increase when using the new Python static typing? pros/cons of each approach?


Solution

  • Static typing in Python doesn't make it a compiled programing language. Therefore, performance-wise, you should always get better performance from Cython (Compiled should always beat Interpreted).

    The main purpose of Python's newly added static typing is to perform type checking in a seamless way, bys sacrificing some of Python's philosophy on the way.

    In short: Cython for speed, Python3.6 for interpreted/more pythonic approach.