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, Marcus