为什么 Python 比 Ruby 快? [英] Why is Python faster than Ruby?

查看:55
本文介绍了为什么 Python 比 Ruby 快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它们似乎有很多相同的特性,但据我所知,Python 2.5 比 1.8.7 快很多.

They seem to share a lot of the same characteristics but as far as I can tell, Python 2.5 is faster than 1.8.7 by a lot.

这背后是否有更深层次的原因?

Is there a deeper underlying reason behind this?

推荐答案

没什么深入,我很确定——这完全是实现选择和成熟度的问题.毕竟不久前,Python 在许多方面都慢了很多!考虑例如:

Nothing deep, I am pretty sure -- it's strictly a matter of implementation choices and maturity. Python was quite a bit slower in many aspects not so long ago, after all! Consider for example:

$ py24 -mtimeit '[i+i for i in xrange(55)]'
100000 loops, best of 3: 10.8 usec per loop
$ py25 -mtimeit '[i+i for i in xrange(55)]'
100000 loops, best of 3: 9.83 usec per loop
$ py26 -mtimeit '[i+i for i in xrange(55)]'
100000 loops, best of 3: 8.12 usec per loop
$ py27 -mtimeit '[i+i for i in xrange(55)]'
100000 loops, best of 3: 6.35 usec per loop

是的,都在同一台机器上(Macbook Pro、2.4 GHz Intel Core 2 Duo、OSX 10.5),所有来自 python.org 的官方"Mac 版本(每个 x 中的最新一个2.x 系列).我没有 2.3 可供检查,但我希望它比 2.4 慢一点.

Yep, all on the same machine (Macbook Pro, 2.4 GHz Intel Core 2 Duo, OSX 10.5), all "official" Mac releases from python.org (latest one of each x in the 2.x series). I have no 2.3 around to check, but I'd expect it to be a wee bit slower than 2.4.

这只是在几乎相同的底层架构的连续版本中,许多充满爱心、艰苦的工作可以实现的加速.不像添加feechurz那么华而不实,但在现实世界中通常更有用!-)

This is just the kinds of speed-up that a lot of loving, painstaking work can achieve among successive releases of pretty much the same underlying architecture. Not as flashy as adding feechurz, but often vastly more useful in the real world!-)

因此,我很确定 Ruby 也可以稳定在一个健全的、性能稳健的底层架构上,然后多年来开始进行稳定的底层性能调整以获得(例如)40在过去的几年里,我们在这里观察到的 Python(至少是某些部分)发生了 % 左右的进一步改进.

I'm pretty sure, therefore, that Ruby can also stabilize on a sound, performance-robust underlying architecture, then start getting a steady stream of under-the-hood performance tweaks over the years to get (e.g.) the 40% or so further improvement we observe here has been happening in (at least some parts of) Python in the last few years.

这篇关于为什么 Python 比 Ruby 快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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