Python 2.x 与 3.x 速度 [英] Python 2.x vs 3.x Speed

查看:67
本文介绍了Python 2.x 与 3.x 速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一名博士生,使用 Python 编写用于研究的代码.我的工作流程通常包括对代码进行小的更改、运行程序、查看结果是否有所改善以及重复该过程.正因为如此,我发现自己花在等待程序运行上的时间比实际工作的时间要多(我知道这是一种常见的经历).我目前在我的系统上使用最新版本的 Python 2,所以我的问题是切换到 Python 3 是否会给我任何速度提升.在这一点上,我真的没有令人信服的理由转向 Python 3,所以如果执行速度相似,我可能只会坚持使用 2.x.我知道我将不得不稍微修改我的代码才能让它在 Python 3 中工作,所以在两个版本上测试它以查看哪个运行速度更快并不是一件容易的事.在我花时间将代码更新到 Python 3 之前,我需要有足够的信心我会获得速度提升.

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.

推荐答案

这篇文章 (archive.org) 说 Python 3.0 在某些方面实际上比 Python 2.6 慢,尽管我觉得这些问题很多都解决了.话虽如此,Numpy 还没有被带到 Python 3.0 中,这就是隐藏了许多高性能(用 c 编写)数字功能的地方.希望它能在 2009 年末或 2010 年初准备就绪.

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.

您不应将性能视为切换到 Python 3 的理由;我认为您不会看到持续的速度提升.

支持 Python 3 的 Numpy 版本已经发布.

Versions of Numpy which support Python 3 have since been released.

Edit2:此答案(以及此问题的其他答案)已过时.

这篇关于Python 2.x 与 3.x 速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆