6 ms·
This power does not come without a price. Ruby is slow. Ruby is generally recognized as being twice as slow as Python, and at least an order of magnitude slower
by pc 18y ago
This power does not come without a price. Ruby is slow. Ruby is generally recognized as being twice as slow as Python, and at least an order of magnitude slower than C++ or Java.
The last two statements don't mean the first is true. Ruby's power is not the reason it's slow. Smalltalk VMs are proof by existence that the Ruby model can be fast. (See: Self, Strongtalk, Gemstone.) MagLev showed that Ruby is basically just an alternative Smalltalk syntax.
Charles Nutter, one of the creators of the JRuby VM for the Ruby language, recently posted an article about optimizations that could be made to the VM, and he improves Ruby performance by as much as twenty times by removing much of Ruby’s power and breaking compatibility.
"Remove much of Ruby's power"? Around 0.2% of Charles's speed-up came from removing the ability to override the primitive math operations. Other than that, his speedups removed none of Ruby's power.
(And nit-picking: Ruby is probably the most powerful programming language on the planet for creating DSLs, or domain specific languages. It can do this because any class or object can be extended, any method overridden, any constant undefined and redefined, and so on, and so forth.
Not true:
>> class StrangeArray < Array; def [](x); x; end; end
nil
a = StrangeArray.new(10)
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
>> a.map{|x| x}
=> [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil] # wrong
>> (0..(a.size - 1)).map{|x| a[x]}
=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # right
I.e., the built-in implementation of Array#map statically refers to the built-in implementation of Array#[].)
(Edited to correct example, as pointed out by hjdivad)
- zitterbewegung 18y agoAlso pretty much any lisp with some type of syntactic macro system.
- hjdivad 18y agoI'm not sure, but I think your counterexample is meant to show you can't replace `Array#pop`. However, that's not what you show -- you show that irb depends on `Array#pop` for its normal usage. Consider: $ ruby -e "class Array; def pop; self.first; end; end; puts [1,2,3].pop" 1
- deleted 18y ago[deleted]
- stcredzero 18y agoThis power does not come without a price. Ruby is slow. ARRRRGH! Why do the expectations of guys from the 80s and early 90s still rule us? There are Lisp and Smalltalk VMs out there that are something like 70X as fast as Ruby 1.8! If you add Traits (library for Mixins) to Smalltalk, it is equivalent to Ruby in power. (1) The one of the biggest misconceptions we have to face in the Computer programming and related professions, is that programmers are on the forefront of technology. Actually, culture lags technology. And in that, I specifically include the culture of computer programmers. The foundations of OO languages like Ruby and Python were set forth in the 70s and 80s. WYSYWIG word processing, ethernet LANs, desktop publishing existed then in pretty much their current forms at Xerox PARC, only slower. The concepts embodied in Dot-NET and Microsoft's Singularity were bandied about in the 60s, 70s, and 80s. The sad thing about our profession is, is that to learn what's coming next, and what's possible you still have to do some digging into history. Things have improved, but because programming is also a cultural artifact, it lags technology like any other cultural artifact. I keep posting this. I used to wonder why it seemed like tilting at windmills. After writing this post, I now realize why. Alan Kay: "The Computer Revolution Hasn't Happened Yet." http://video.google.com/videoplay?docid=-2950949730059754521 http://video.google.com/videoplay?docid=-2950949730059754521 (1) - In fact, it is homomorphically equivalent. This is precisely why something like Maglev can work. Another interesting thing -- many Lisps are also homomorphically equivalent to at least 90% of the languages out there. And one could probably take just about any Lisp and give it the power of the other 10% (like Erlang) with moderate effort.
- jhancock 18y agothanks for saving me the time. my thoughts exactly! History should be the first thing we teach new programmers.
- sho 18y agoThere are NOT SmallTalk libraries out there that are 70x faster than Ruby - that would be faster than raw C (Ruby is about 30x slower). Are you trying to say that SmallTalk is faster on average than raw C? So why isn't everything written in SmallTalk? And I'll believe Maglev's outlandish performance claims if and when I ever see them realised. If they are anything like those claimed at RailsConf 2008 (50x or thereabouts), I'll eat my hat and any other hats anyone cares to send me. I say this as someone who would probably seriously consider murder if it would make my Rails apps run 10x faster. I want it to be true. I just don't think it is, unfortunately. And one could probably take just about any Lisp and give it the power of the other 10% (like Erlang) with moderate effort. I keep hearing things like this, but no-one ever does it.
- deleted 18y ago[deleted]