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

梦想的初衷 提交于 2019-11-29 01:54:51

问题


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


回答1:


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!




回答2:


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




回答3:


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.




回答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?




回答5:


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.




回答6:


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.



来源:https://stackoverflow.com/questions/170426/performance-python-3-x-vs-python-2-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!