If you want to use the same code unmodified *and* your code uses type hints, then you should use mypyc [1].
There are times that it generates faster code than Cython! Of course with Cython you can tweak it and push its limits with various optimizations and other techniques, but for using your existing code as it is and gain massive performance improvements, mypyc it's a must!
Code sample:
import time
def fib(n: int) -> int:
if n <= 1:
return n
else:
return fib(n-2) + fib(n-1)
startTime = time.time()
fib(35)
duration = time.time() - startTime
msduration = duration * 1000.0
uduration = msduration * 1000.0
print(f'{duration:.6f} seconds, {msduration:.2f} ms, {uduration:.2f} μs')
$ python3 mypyfib.py
1.452477 seconds, 1452.48 ms, 1452477.22 μs
$ # the same code compiled with `mypyc mypyfib.py` produces the following:
$ python3 -c "import mypyfib"
0.063701 seconds, 63.70 ms, 63700.91 μs
This is huge, if you think about it! 95.61% reduction in time
2180.15% increase in performance
22.80x faster
[1] https://github.com/mypyc/mypyc