From: ptkwt@...1.aracnet.com (Phil Tomson) Date: 2003-04-12T03:09:41+09:00 Subject: Re: Need IO Optimization help In article <20030411115918.A35958@linnet.org>, Brian Candler wrote: >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. Well, if you'd prefer to use Ruby then putting up with a couple of lines of ugliness so you could benefit from using Ruby for the rest of the program might be worth it. This idea (to overwrite an existing string) might very well be a good way to acheive the speed-up that Jim is looking for. Perhaps a C extension which does this would be a big win - call it FastIO or something. You have to remember that he mentioned the need to read in files which are several hundred MB in size - any (even small) performance gain will help save a lot of time when it comes to reading large files. > >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. However, when it comes to comparing OO Perl speed and Ruby, method dispatch in Ruby is faster. > >Or just buy a dual-CPU box :-) Wouldn't help in this case. Phil