Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Performance: Python 3.x vs Python 2.x [closed]

Tags:

On a question of just performance, how does Python 3 compare to Python 2.x?

like image 875
Scott Bennett-McLeish Avatar asked Oct 04 '08 14:10

Scott Bennett-McLeish


People also ask

Is python3 faster than Python 2?

So is Python 3 faster than Python 2? Yes! in almost all tests. The notable exceptions were the crypto_paes test, where Python 3 was 1.35x slower (because of the integer types), python_startup as 1.39x slower.

What is the difference between Python 2 x and Python 3 x?

In python 2. x, “print” is treated as a statement and python 3. x explicitly treats “print” as a function. This means we need to pass the items inside your print to the function parentheses in the standard way otherwise you will get a syntax error.

Which Python version is fastest?

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.

Why is Python 3 better than 2?

Python 3 better supports AI, machine learning, and data science. It has more updates that don't exist in Python 2. Python 3 is still supported and has a wide range of users to assist support, while Python 2 was sunsetted in 2020. Python 3 is one of the fastest-growing programming languages.


2 Answers

3.0 is slower than 2.5 on official benchmarks. From "What’s New in Python 3.0":

The net result of the 3.0 generalizations is that Python 3.0 runs the pystone benchmark around 10% slower than Python 2.5. Most likely the biggest cause is the removal of special-casing for small integers. There’s room for improvement, but it will happen after 3.0 is released!

like image 145
Constantin Avatar answered Dec 21 '22 19:12

Constantin


I'd say any difference will be below trivial. For example, looping over a list will be the exact same.

The idea behind Python 3 is to clean up the language syntax itself - remove ambigious stuff like except Exception1, Exception2, cleanup the standard modules (no urllib, urllib2, httplib etc).

There really isn't much you can do to improve it's performance, although I imagine stuff like the garbage collection and memory management code will have had some tweaks, but it's not going to be a "wow, my database statistic generation code completes in half the time!" improvement - that's something you get by improving the code, rather than the language!

Really, performance of the language is irrelevant - all interpreted languages basically function at the same speed. Why I find Python "faster" is all the built-in moudles, and the nice-to-write syntax - something that has been improved in Python3, so I guess in those terms, yes, python3's performance is better then python2.x..

like image 34
dbr Avatar answered Dec 21 '22 19:12

dbr