Python 2.x vs 3.x Speed

后端 未结 5 1599
礼貌的吻别
礼貌的吻别 2021-02-06 22:32

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

相关标签:
5条回答
  • 2021-02-06 22:55

    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.

    0 讨论(0)
  • 2021-02-06 23:07

    I can't answer the root of your question, but if you read anything regarding the sluggish performance of the io module please disregard it. The were definitely performance issues in Python 3.0, but they were largely resolved in Python 3.1.

    0 讨论(0)
  • 2021-02-06 23:11

    I have phylogenetics analysis that takes a long time to run, and uses about a half-dozen python scripts as well as other bioinformatics software (muscle, clustal, blast, even R!). I use temp files to save intermediate results and a master script with the subprocess module to glue all the pieces together. It's easy to change the master to run only the modified parts that I want to test. But, if the changes are being made to early steps, and you only know how good it is at the end of the whole process, then this strategy wouldn't help much.

    0 讨论(0)
  • 2021-02-06 23:12

    Right now, speed on Python 3 is more or less the same as Python 2... If you're looking for speed, it's not on Python 3 vs Python 2 but in other tools like Psyco, Cython, etc...

    But, very recently, there have arisen plans to merge Unladen Swallow, the Google project to implement a JIT over Python with Python 3. Of course, it won't be very soon, but, in some time, maybe the speed will increase noticeably on Python 3 over Python 2. They claim to have already increased speed on a 10% (on Python 2). Their objective is increasing the speed to 5x.

    For more information, see PEP 3146

    EDIT: Just as Brian remarks, PEP 3146 was retired.

    0 讨论(0)
  • 2021-02-06 23:13

    Try refining the algorithms or changing the data structures used. That's usually the best way to get an increase in performance.

    0 讨论(0)
提交回复
热议问题