Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why shouldn't I use PyPy over CPython if PyPy is 6.3 times faster?

I've been hearing a lot about the PyPy project. They claim it is 6.3 times faster than the CPython interpreter on their site.

Whenever we talk about dynamic languages like Python, speed is one of the top issues. To solve this, they say PyPy is 6.3 times faster.

The second issue is parallelism, the infamous Global Interpreter Lock (GIL). For this, PyPy says it can give GIL-less Python.

If PyPy can solve these great challenges, what are its weaknesses that are preventing wider adoption? That is to say, what's preventing someone like me, a typical Python developer, from switching to PyPy right now?

like image 971
chhantyal Avatar asked Sep 22 '13 17:09

chhantyal


People also ask

Which is faster CPython or PyPy?

The PyPy implementation is 16 times faster than the CPython implementation and about 3 times slower than the Cython implementation. This is fascinating since PyPy is running the exact same pure Python code as the CPython implementation – it shows the power of PyPy's JIT compiler.

Should I use PyPy or CPython?

PyPy works best with pure Python apps Numpy, for instance, works very well with PyPy now. But if you want maximum compatibility with C extensions, use CPython.

How much faster is PyPy?

In this small synthetic benchmark, PyPy is roughly 94 times as fast as Python! For more serious benchmarks, you can take a look at the PyPy Speed Center, where the developers run nightly benchmarks with different executables.

Is PyPy compatible with CPython?

Speed: thanks to its Just-in-Time compiler, Python programs often run faster on PyPy. (What is a JIT compiler?) Memory usage: memory-hungry Python programs (several hundreds of MBs or more) might end up taking less space than they do in CPython. Compatibility: PyPy is highly compatible with existing python code.


1 Answers

NOTE: PyPy is more mature and better supported now than it was in 2013, when this question was asked. Avoid drawing conclusions from out-of-date information.


  1. PyPy, as others have been quick to mention, has tenuous support for C extensions. It has support, but typically at slower-than-Python speeds and it's iffy at best. Hence a lot of modules simply require CPython. PyPy doesn't support numpy. Some extensions are still not supported (Pandas, SciPy, etc.), take a look at the list of supported packages before making the change. Note that many packages marked unsupported on the list are now supported.
  2. Python 3 support is experimental at the moment. has just reached stable! As of 20th June 2014, PyPy3 2.3.1 - Fulcrum is out!
  3. PyPy sometimes isn't actually faster for "scripts", which a lot of people use Python for. These are the short-running programs that do something simple and small. Because PyPy is a JIT compiler its main advantages come from long run times and simple types (such as numbers). PyPy's pre-JIT speeds can be bad compared to CPython.
  4. Inertia. Moving to PyPy often requires retooling, which for some people and organizations is simply too much work.

Those are the main reasons that affect me, I'd say.

like image 156
Veedrac Avatar answered Oct 17 '22 04:10

Veedrac