From: Brian Candler Date: 2003-04-11T19:59:28+09:00 Subject: Re: Need IO Optimization help On Fri, Apr 11, 2003 at 06:47:27PM +0900, Jim Freeze wrote: > On Friday, 11 April 2003 at 17:47:39 +0900, Robert Klemme wrote: > > Even if there are no improvements possible you should judge the effort of > > improving speed of ruby vs. perl or others agains the effort to maintain a > > changed ruby and the efforts saved by rubys higher development speed. For > > some script it's surely more efficient to write it in one hour and have it > > run in another than to tweak a high performance perl script in four hours > > that then runs in 15 minutes. > > For new scripts what you say is true. But I can't accept the fact > that there are no improvements possible. And Ruby has no advantage > when the Perl scripts already exist and are not being changed. But Ruby has some fundamental disadvantages compared to Perl for this sort of program. For example, count += 1 requires a method dispatch, and gets requires the creation of a new object each time round the loop (and the corresponding cleaning up of old objects), whereas when perl assigns to $_ I think it's just overwriting a global string buffer. Both these 'handicaps' spring from Ruby's design which makes the writing of large programs far more elegant, and I suspect when you're not just chucking strings and around but doing operations with complex objects, the performance difference will become less significant. I suppose you could tweak the language to make it like Perl - for example when reading lines have a method to overwrite an existing string instead of allocating a new one: while $_.gets! .. perhaps end But who wants to write ugly code like that for a small performance gain? You might as well just use Perl in the first place. In Perl a scalar is a scalar (except when it's a reference!!) - in Ruby everything's an object. It's a big win for writing concise code quicky, and I'm happy to take the performance hit. If it's "too slow to be useful" at speed X then it's probably too slow to be useful at speed 2X either. In that case you need a fundamental rethink to make it run at speed 10X or 100X. Or just buy a dual-CPU box :-) Regards, Brian.