SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 55
Thread: Ruby is slow? - some experience
-
Sep 27, 2005, 13:01 #1
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Ruby is slow? - some experience
Hi.
Just been porting some PHP/Perl code to ruby and timing the results. I have found slap dash ruby code to be an order of magnitude slower than slap dash PHP code. All those little blocks reading files rather than File.readlines hurts badly, whereas the PHP file() and array_map() functions are very natural. PHP arrays are blindingly fast and I have a new found respect for them (although they suck up memory).
With a bit of optimisation things changed. I/O is roughly comparible, maybe a bit slower in ruby. Unfortunately there is no equivalent of file_put_contents(), but I was mainly reading.
Ruby hashes are about the same as PHP hashes. PHP hashes preserve ordering though, which can save you a lot of processing later.
Ruby arrays seem to be about 3-5 times slower than PHP when looping through. Even the Array.collect {} syntax is a lot slower than array_map().
Ruby string concatenation is much slower. I don't have a multiple, but the profiled PHP code didn't show it as even being an issue, where as it came to 20% odd of the processing in Ruby.
I was doing real world stuff here with big data sets, manipulating about 200meg of data in memory. In PHP you have to set the memory limit and timeout of course, which is an irritation. My gut feel though is that the ruby code comes out 1.5 times slower after an hour of optimisation. The optimisation had a big impact on the ruby code, but I could not really get PHP to go any quicker.
The problem space was a lot of string, hash and file manipulation. It was much faster to write the Ruby code, but I wrote it the second time around in ruby so I think that was the real reason. For me there is currently little difference in productivity.
Anyways, any other people getting the same experiences?
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Sep 27, 2005, 13:18 #2
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by lastcraft
Code:File.open (stuff here) { |f| f << YourDataArray.join('\n') }
Ruby hashes are about the same as PHP hashes. PHP hashes preserve ordering though, which can save you a lot of processing later.
Ruby arrays seem to be about 3-5 times slower than PHP when looping through. Even the Array.collect {} syntax is a lot slower than array_map().
Ruby string concatenation is much slower. I don't have a multiple, but the profiled PHP code didn't show it as even being an issue, where as it came to 20% odd of the processing in Ruby.
I was doing real world stuff here with big data sets, manipulating about 200meg of data in memory. In PHP you have to set the memory limit and timeout of course, which is an irritation. My gut feel though is that the ruby code comes out 1.5 times slower after an hour of optimisation. The optimisation had a big impact on the ruby code, but I could not really get PHP to go any quicker.
The problem space was a lot of string, hash and file manipulation. It was much faster to write the Ruby code, but I wrote it the second time around in ruby so I think that was the real reason. For me there is currently little difference in productivity.
Anyways, any other people getting the same experiences?
-
Sep 27, 2005, 13:23 #3
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well, with the risk of repeating another post of mine on another thread:
Ruby's interpretter SUCKS -> it's the worst I've ever seen, let's hope Ruby 2.0 which prommises better performance is revealed soon enough.
Python is also object oriented and it's faster (as fast as PHP). So there is hope.
-
Sep 27, 2005, 13:30 #4
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
http://shootout.alioth.debian.org/be...y&sort=fullcpu
the difference between Perl and Ruby aren't that high (aprox 4x)
http://shootout.alioth.debian.org/be...p&sort=fullcpu
that's PHP that is still slower than Perl (a bytecode engine will surelly fix this)
http://shootout.alioth.debian.org/be...n&sort=fullcpu
and Python apparently is head to head with Perl
So, if Python can do it, so will Ruby. Problem is Ruby is very new (in the rest of the world outside Japan at least)
-
Sep 27, 2005, 13:49 #5
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
-
Sep 27, 2005, 13:57 #6
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
-
Sep 27, 2005, 22:45 #7
- Join Date
- Jun 2004
- Location
- Stockholm, Sweden
- Posts
- 148
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Perl is version 5.8, PHP is version 5.x, Python (the latest branch anyway) is 2.4.x.
Ruby is only at 1.8.x.
I think this accounts for most of the performance issues, the Ruby interpreter has up until now focused on creating a Good Language and a Stable Environment. Now with version 2 they are focusing on Fast Execution.If there is a way to overcome the suffering, there is no need to worry; if there is no way to overcome the suffering, there is no point to worry.
- Shantideva
-
Sep 28, 2005, 06:22 #8
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by KTottE
Example: until PHP 3, PHP was a joke, so I think it's crystal clear that 1.8.3 in Ruby vs 5.x in PHP vs 5.8 in Perl doesn't mean sh*it
Originally Posted by Sgarissta
Just kidding (or not?)
Originally Posted by Sgarissta
I know Python and I can testify that Python is OOP. And in Python "EVERYTHING IS AN OBJECT" too
There are differences in phylosophies though. Ruby has indeed the concept of message passing inheritted from Smaltalk while in Python there is a clear difference between properties and methods because the "method" is still a central construct. But it only depends on what you find as being OOP i.e. are you sure "message passing" is the only way ?
Also a good language is a language that can evolve over time. Python has indeed evolved to be "completelly OOP", but are you sure Ruby will evolve in the future as beautifull as Python did until now ? Because ideeas and phylosophies change, and evolutions and sometimes revolutions are required.
Python is a wonderfull language too, so please don't post any more FUDs and flame-baits.
PS: I quite like "self" so it's only a matter of taste.
-
Sep 28, 2005, 09:20 #9
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
Also a good language is a language that can evolve over time. Python has indeed evolved to be "completelly OOP", but are you sure Ruby will evolve in the future as beautifull as Python did until now ? Because ideeas and phylosophies change, and evolutions and sometimes revolutions are required.
Python is a wonderfull language too, so please don't post any more FUDs and flame-baits.
-
Sep 28, 2005, 11:13 #10
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Sgarissta
And no, there shouldn't be any performance penalties for Ruby because it has a more pronounced message passing philosophy.
Ruby behaves exactly the same as Python when accessing methods or properties. The only thing that's different is that in Python the method itself is an object and in Ruby the method can be wrapped inside an object (Proc). And that's a huge difference in philosophy. But when actually calling a method on an object, there is no difference. The same message passing technique applies to both since they are both dynamic.
That is why there shouldn't be any difference between Python and Ruby in performance just because Ruby is OOP. And that's why Ruby can be at least as fast as Python.
Off Topic:
A note about the self parameter: it is still available in recent versions because it is pythonic to have access to all inner workings. For example, in python, you don't have private variables, you only have a way to hide them from the class dictionary, but nothing else prevents you from accessing it. It is just pythonic not to hide stuff like that. In few words: "Easy to use, but visible". It is only a matter of taste, as I said.
-
Sep 28, 2005, 11:54 #11
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by bonefry
That is why there shouldn't be any difference between Python and Ruby in performance just because Ruby is OOP. And that's why Ruby can be at least as fast as Python.
-
Sep 29, 2005, 02:29 #12
- Join Date
- Nov 2004
- Location
- Romania
- Posts
- 848
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Sgarissta
Code:f = obj.execMethod f()
Originally Posted by Sgarissta
-
Sep 29, 2005, 07:35 #13
- Join Date
- Jan 2003
- Posts
- 5,748
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Honestly folks, I've just got to laugh... All this steam about Ruby being the best thing since sliced cheese, etc etc etc.
And it's slow...
Python is also object oriented and it's faster (as fast as PHP). So there is hope.
I still don't, even if there was to be an inprovement on performance. Ruby is said by many on these forums that it is a lot more flexible, etc. Well, for that flexibility, there is also a penalty I suppose.
It's ironic to read someone say that there is hope, in the context of being compared to something like Python. I've always had the vision that Python was the better language of the two anyways, but reading this just goes and confirms it.
Ruby doesn't rock people. It never has, and I'm sorry if this comes across as being negative, but I'm being honest if nothing else.
-
Sep 29, 2005, 07:50 #14
Why is everybody getting hung up on speed? Hardware is cheap, programmers aren't.
Seriously, as has been said many times, if we were all hung up about speed, surely we'd be writing everything in C?
-
Sep 29, 2005, 07:54 #15
- Join Date
- Dec 2004
- Location
- virginia
- Posts
- 188
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ruby is only on version 1.x
Was PHP as fast as it is now when it was on version 1.x?
-
Sep 29, 2005, 07:57 #16
Originally Posted by joflow
-
Sep 29, 2005, 08:40 #17
- Join Date
- Dec 2004
- Location
- virginia
- Posts
- 188
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by vgarcia
So I think anyone writing Ruby off before it atleast has time to mature is probably doing themselves a great disservice.
-
Sep 29, 2005, 08:47 #18
Originally Posted by joflow
-
Sep 29, 2005, 08:50 #19
No offence, but your reasoning on the version number is a bit off - like bonefry said in the other thread, the versioning schemes are not comparable. Ruby might be 1.8.2, but has been around for a decade. Its had plenty of time to mature, and as a language, it has.
As has been stated, the problem generally lies with the interpreter, not the language, and I believe this is a target for 2.0.
Also, PHP started life as nothing more than a template language for Perl, so again, hardly a fair comparison either way.
-
Sep 29, 2005, 08:58 #20
- Join Date
- Jul 2004
- Location
- Oklahoma
- Posts
- 119
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Dr Livingston
Do you feel like a better person for letting us all know this? Honestly I couldn't give a crap about your opinion on a language you haven't used, "gut feeling" or not, sorry if that comes across as negative, I'm just being honest. I LIKE the way Ruby code comes out, I like the way Ruby code "feels". I LIKE the flexibility of Ruby. Please, if you don't care about Ruby at all (which you seem to keep saying, who are you trying to convince?), get the hell out of of the Ruby forum.
I'll freely admit Ruby is slower than its competition in many ways, but I don't care. If it was all about speed, we'd all still be writing hand-crafted assembly.
Have fun ripping on other people's choices!
-
Sep 29, 2005, 09:11 #21
- Join Date
- Apr 2003
- Location
- London
- Posts
- 2,423
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Hi...
Originally Posted by Luke Redpath
The caveat is that Ruby does require some sacrifice of developer time in optimisation for long jobs, as unoptimised it can end up a total dog. That has to be subtracted from a possibly faster development speed for the initial prototype.
Thanks for the IO tips (again). They seem to make a marginal, but measurable, difference. Unfortuanately I have ripped out all of the timing statements I put in, so I cannot give any figures now.
I like this forum already.
yours, MarcusMarcus Baker
Testing: SimpleTest, Cgreen, Fakemail
Other: Phemto dependency injector
Books: PHP in Action, 97 things
-
Sep 29, 2005, 09:45 #22
- Join Date
- Dec 2004
- Location
- virginia
- Posts
- 188
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Luke Redpath
Since its been around for 10 years...does this mean that development has been slow (if this is the case, maybe development will pick up now that there is alot of interest in Ruby)? If this is the case then it there would be hope that future versions will be faster but if Ruby has gone through steady development for 10 years and is still slow then I'd now have to side with Dr. Livingston in saying that Ruby pretty much sucks.
-
Sep 29, 2005, 09:45 #23
Hi Marcus
My post should have included a quote really as out of context I guess its sounds like an attack at this thread in general. It wasn't, and wasn't suggested that you were getting "bothered" by the speed either. I was more bothered by Dr Livingstone's seeminly pointless post about why Ruby's speed could firmly tick another box in his "Why Python is better" list, and others who were getting hung up over the issue.
-
Sep 29, 2005, 09:47 #24
Originally Posted by joflow
If you don't really use Ruby and have come to the (rather worthless) conclusion that it sucks because of its speed, despite its many positives, then I guess you don't really have much else to contribute do you? Ruby is generally fast enough for most uses. This doesn't mean that it shouldn't be optimised, or could do with a better interpreter, nor should it mean you don't use it just because there are faster languages.
Do some people seriously have nothing better to do than come here to bash Ruby? Can we please have a bit of moderation in this forum? Go and troll elsewhere.
-
Sep 29, 2005, 09:50 #25
- Join Date
- Dec 2004
- Location
- virginia
- Posts
- 188
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well then I guess there is hope of speed improvements then.
I'm not really bashing ruby...I've never used it personally. I'm in the process of setting up a site with ruby as a trial run and I'll begin development as soon as I find some good tutorials on rails (seems hard to find good resources on the framework).
But every forum I've been too seems to have at some complaints about the speed so I assumed it was a huge problem. I'll hold off further judgement until I've tested it out myself and see if its fast enough for my needs.
Bookmarks