Performance: Python 3.x vs Python 2.x [closed]
Asked Answered
A

6

24

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

Arpeggio answered 4/10, 2008 at 14:28 Comment(2)
Two years after this question was asked, I wonder if the answer is still the same.Isahella
SEVEN years after this question was asked, the answer is still the same.Lascivious
K
29

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!

Kapoor answered 4/10, 2008 at 16:29 Comment(1)
This is still generally true in 2015, if the code in question has a lot of string operations, Python 2.7 is generally faster than Python 3.5, as of Nov 2015.Lascivious
K
7

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..

Kinetics answered 4/10, 2008 at 15:29 Comment(2)
"all interpreted languages basically function at the same speed" is very much not true. Interpreted code paths can be compiled down to native code, see the recent Javascript VM competitors.Lamphere
that means nothing about the language, but the compilers written for it. You could have a python compiler and it'd be roughly as fast as a javascript one.Tomi
L
5

The IO library has been completely redesigned, and the new implementation is in pure Python. Whilst this is a functional improvement, it is at present much slower. Work is afoot to rewrite the bulk of the new system in C. For details see these bug reports.

Lananna answered 27/1, 2009 at 16:32 Comment(0)
L
4

I think ultimately it is too early to make that kind of comparison just yet. Wait until it is out of beta before benchmarking it. The interpreter will probably be polished enormously before the release but overall i think for most uses the performance would be comparable and if you are running a really speed conscious app is python really the right language to be using?

Lutenist answered 4/10, 2008 at 18:28 Comment(0)
G
3

Unless there are plans for a new VM of some kind (and I haven't heard of any such plans), there is all the reason to believe that in the long run the performance of Py3K will, at least asymptotically, equal that of 2.5

It may take a few months, but will eventually happen, as nothing in the new features of Py3k is inherently less performant.

To conclude, I don't think there's place to worry about it. Neither to hope for a major improvement of some kind.

Grenville answered 4/10, 2008 at 18:23 Comment(1)
(Update 30.03.2010): This answer isn't very relevant today, since unladen-swallow is going to be merged into Python 3 and provide noticeable speedups. To be fair, this is a new VM :-)Grenville
E
0

I don't if it faster now, but I have to expect that it eventually will be because that is where new performance work will happen and not all of that will be backported.

Exorbitance answered 4/10, 2008 at 16:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.