Thanks alot Chas... this is a great example....
Anu
On 10/11/07, Chas. Owens <[EMAIL PROTECTED]> wrote:
>
> On 10/10/07, newBee <[EMAIL PROTECTED]> wrote:
> > On Oct 9, 8:18 pm, [EMAIL PROTECTED] (Jeff Pang) wrote:
> > > 2007/10/10, Dr.Ruud <[EMAIL PROTECTED]>:
> > >
> > > > No need for (), so you can write:
> > >
> > > > m/tony|anthony/i
> > >
> > > or,
> > > /tony/i || /anthony/i
> > >
> > > this is faster than /tony|anthony/i.
> >
> > Thanks to all you guys... after I published the question I didn't get
> > a chance to look so I used something like this which did the job /
> > \b(tony|anthony)\b/i .. I think i am going to see the performance
> > difference between that and /tony/i || /anthony/i ... do we have a
> > inbuilt time function in perl..?
> snip
>
> If you want to compare two or more implementations of something in
> Perl then the Benchmark module is your friend. It is used like this:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Benchmark;
>
> my $test = shift;
> my $time = shift || -2;
>
> my @data = (
> "He took Tony to the store.",
> "An anteater took a look at Anthony.",
> "There is no Tonya here.",
> "It doesn't match Anthonye."
> );
>
> my %subs = (
> capturing_alternation => sub {
> my @results;
> push @results, scalar(/\b(tony|anthony)\b/i) for @data;
> return @results;
> },
> noncapturing_alternation => sub {
> my @results;
> push @results, scalar(/\b(?:tony|anthony)\b/i) for @data;
> return @results;
> },
> or => sub {
> my @results;
> push @results, scalar(/\btony\b/i or /\banthony\b/i) for
> @data;
> return @results;
> },
> );
>
> if ($test) {
> for my $sub (keys %subs) {
> print "$sub => ", map({ "[$_]" } $subs{$sub}()), "\n";;
> }
> }
>
> Benchmark::cmpthese($time, \%subs);
>
--
Anuradha Uduwage