I'm a PhD student and use Python to write the code I use for my research. My workflow often consists of making a small change to the code, running the program, seeing whether the results improved, and repeating the process. Because of this, I find myself spending more time waiting for my program to run than I do actually working on it (a common experience, I know). I'm currently using the most recent version of Python 2 on my system, so my question is whether switching to Python 3 is going to give me any speed boost or not. At this point, I don't really have a compelling reason to move to Python 3, so if the execution speeds are similar, I'll probably just stick with 2.x. I know I'm going to have to modify my code a bit to get it working in Python 3, so it's not trivial to just test it on both versions to see which runs faster. I'd need to be reasonably confident I will get a speed improvement before I spend the time updating my code to Python 3.
Python 3.3 comes faster than Python 2.7.
Python 3.7 is 1.19x faster than Python 2.7, but the only Python 3. x release to beat the Python 2.7 benchmark I ran. The speed.python.org benchmark shows similar results. PyPy smashes any of the CPython results, but with PyPy3 twice as slow as PyPy.
In Python 3, print is considered to be a function and not a statement. In Python 2, strings are stored as ASCII by default. In Python 3, strings are stored as UNICODE by default. On the division of two integers, we get an integral value in Python 2.
maxint was dropped from Python 3, but the integer value is basically the same. The speed difference in Python 2 is thus limited to the first (2 ** 63) - 1 integers on 64-bit, (2 ** 31) - 1 integers on 32 bit systems.
This article (archive.org) said that there were a few points where Python 3.0 was actually slower than Python 2.6, though I think many of these issues were resolved. That being said, Numpy hasn't been brought over to Python 3.0 yet and that's where a lot of the high performance (written in c) number functionality stuff is hiding. Hopefully it will be ready late 2009 or early 2010.
You should not consider performance to be a justification to switch to Python 3; I don't think you'll see a consistent speed improvement.
Edit: Versions of Numpy which support Python 3 have since been released.
Edit2: This answer (and other answers to this question) are outdated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With