--000e0cd18476350da6047c533b48
Content-Type: text/plain; charset=ISO-8859-1

On Mon, Jan 4, 2010 at 2:54 AM, Ruby Newbee <rubynewbee / gmail.com> wrote:

> Hi,
>
> I wrote this message without other purpose, just show a result for
> comparison. :-)
>
> First I got the page which will be used for analysis (got all domain
> names from it):
>
> wget http://www.265.com/Kexue_Jishu/
>
> It will get an index.html page.
>
> Then I run this ruby script:
>
> #!/usr/bin/ruby
>
> f  ile.open("index.html")
>
> f.each_line do |c|
>    puts $1 if /hrefttp:\/\/(.*?)\/.*" targetblank"/ c
> end
>
> f.close
>
>
> And this perl script:
>
> #!/usr/bin/perl
>
> open HD,"index.html" or die $!;
> while(<HD>) {
>    print $1,"\n" if /hrefttp:\/\/(.*?)\/.*" targetblank"/;
> }
> close HD;
>
>
> When using "time" command to see the running time, I saw ruby is
> slower than perl (maybe due to the regex?).
>
> Ruby's:
>
> real    0m0.013s
> user    0m0.012s
> sys     0m0.000s
>
> Perl's:
>
> real    0m0.004s
> user    0m0.004s
> sys     0m0.000s
>
> Both versions:
>
> # ruby -v
> ruby 1.9.1p243 (2009-07-16 revision 24175) [i686-linux]
>
> # perl -v
> This is perl, v5.8.8 built for i486-linux-thread-multi
>
>
> Yes that's the result, but not influence me to love ruby.
>
>
> Thanks.
> Jenn.
>
>
It seems like most of the time would be spent loading the environment and
printing the output, making it difficult to compare regexp speeds.

Anyway, just wanted to say the Ruby one can be done in a more succinct
syntax:

File.open("index.html").each do |c|
  puts $1 if /hrefttp:\/\/(.*?)\/.*" targetblank"/ c
end

--000e0cd18476350da6047c533b48--