From: gga Date: 2007-01-19T05:20:19+09:00 Subject: Re: Ruby and Python, questions (not a flamewar!) Drew Olson wrote: > > 1) I've read that Python is faster than ruby. How is this possible if > they're both interpreted languages written in C? Is it marginally or > substantially faster? Will this change with the release of YARV? Even if > ruby becomes faster with YARV, wouldn't this mean that the underlying > language, before producing the bytecode, is slower than Python? > Ok, this is subjective, so take it with a grain of salt, but... Yes. Standard C Python is (slightly) faster for mathematical operations and the like (about 10-20%). It is a tad slower, imo, for object inheritance (about 5-10%) and, albeit I have never quite benchmarked, I would bet it is also slower for string operations (as Python's strings are immutable, unlike Ruby's). YARV, as it already appears in 1.9, will make Ruby roughly as fast as C Python (some preliminary tests are still a tiny little bit faster in Python, others are already faster in YARV). YARV does not look like it will make Ruby faster than Python+Psyco, thou. While the alioth shootout is often criticized for its unfairness (and there is some truth to that, particularly with the python benchmarks where I've often seen some questionable code) and their benchmarks lean heavily on measuring just numerical performance, the overall results of still show relatively correct trends in performance. See: http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=iron&lang2=yarv http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=python&lang2=yarv http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang=psyco&lang2=yarv YARV, however, appears to me a slightly ahead of the game in terms of making Ruby truly multi-threaded. The Python GIL (global lock) seems like it is a big thorn into the design of the C Python interpreter. Personally, I don't think performance is a strength of Python at all anymore. In terms on scripting language performance, LuaJIT has left YARV, CPython+Psyco, and Perl quite in the dust if you ask me (this is not so surprising as Lua is a much simpler language, albeit somewhat less friendly). The reasons why C Python is faster than Ruby are probably deep embedded in how their source code is coded, but, out of the top of my head: - C Python relies mainly on reference counting for all its objects by default, while Ruby uses a pretty inefficient garbage collector. - C Python uses byte-code compilation, while Ruby (sans YARV) does not. - C Python does have a couple of constructs that are efficiently optimized by the interpreter (list comprehensions, for example). The equivalent Ruby block code is usually not optimized at all. > 2) Why are many mainstream organizations using Python rather than ruby? > Is it simply an age issue (Python has been around longer)? Is it a > performance issue? Is this changing currently? Age, performance, origins of Ruby, and lack of knowledge about it till about 3-4 years ago. I'd say Ruby really became "mature" as a language with v1.8 (only about 4 years ago) and truly popular with Ruby on Rails (RoR), just two years ago. > > 3) how did they gain this foothold? Why not ruby for standard > Linux config scripts? > Probably for the same reasons as 2). > Thanks so much for any answers you all have. I can only hope that ruby > will begin to rival Python in the "mainstream" (whatever this means). > Ruby is already quite mainstream, and in a domain that matters quite a lot, which is the web. Thanks to RoR, most new websites now built are likely to be built around Ruby than other technologies. Albeit python did get (and probably still is) used in some places around the web, for the most part python has struggled to achieve the massive user base on the web that, say, Perl, PHP, Java or Ruby have obtained at some point of their lives. Ruby's popularity is still clearly on the upswing, unlike python which seems more or less stuck, if you are to believe some of the statistics published for 2006 (O'Reilley books, TIOBE index, etc).