PyPy: a faster drop-in replacement for CPython interpreter

In python, if you are scripting an algorithm or writing an intensive program, running it is often very slow, especially with a repl’s modest computing resources.

However, you can get a free performance gain by using PyPy, a different python implementation which has a JIT compiler, instead of CPython (the default implementation). This is without rewriting your program at all.

PyPy template

This is for those who need to compute something but don’t want to learn a lower level language or are not as comfortable with them. Python’s features make it quick and easy to script an algorithm (depending on your preferences), but usually at the cost of performance.

Notes:
Performance gains are less for programs that:

  • spend most of their time in external libraries, extensions, or builtin functions, which are all usually written in C
  • are short scripts that run quickly (the program must run for some time for the JIT compiler to optimize)

The best performance gains are for pure python computing algorithms.

Packages are available. (pygame does not work apparently.)

5 Likes