From: Florian Frank Date: 2003-08-27T00:13:24+09:00 Subject: Re: Ruby launching system apps? On 2003-08-26 23:03:55 +0900, Bermejo, Rodrigo wrote: > on ruby 1.6.8 > > time ruby -p -e 'gsub("sed","ruby")' file_with_1000000_sed_lines > 7.61s user 2.02s system 35% cpu 27.161 total > > time sed s/sed/ruby/g file_with_1000000_sed_lines > 2.05s user 1.71s system 32% cpu 11.571 total > > ...I expected other results...but (I hope) it's improved on 1.8 ( > I could not test it now on 1.8 ) I don't think that it is fair to compare ruby with sed because Ruby's regular expressions are better than extended REs (ERE) while sed seems to support at most basic regular expressions (BRE). If you only need a subset it's no wonder that sed is faster and a good choice for optimization. Compared to Perl's RE Ruby is not too bad and I suppose that Perl's RE are very highly optimized for speed. [flori@lambda big](130)$ echo sed: ; time sed s/sed/ruby/g sed.txt > /dev/null ; echo ruby: ; time ruby -p -e 'gsub(/sed/,%q/ruby/)' sed.txt > /dev/null ; echo perl: ; time perl -p -e 's/sed/ruby/g' sed.txt > /dev/null sed: real 0m1.793s user 0m1.670s sys 0m0.016s ruby: real 0m13.141s user 0m11.953s sys 0m0.131s perl: real 0m9.773s user 0m9.109s sys 0m0.104s [flori@lambda flori](0)$ ruby -e 'puts "%.2f" % ((11.953 / 9.109 - 1) * 100)' 31.22 Perl is ca. 30% faster than Ruby, that's not too much. Given the fact that in Ruby regular expressions are first class citizens and full flexed objects after beeing created, while you have to use work arounds like qr/.../ if you want to pass them around in Perl. -- It is by the goodness of God that in our country we have those three unspeakably precious things: freedom of speech, freedom of conscience, and the prudence never to practice either. -- Mark Twain, More Tramps Abroad