[rt-users] fun with Klez

darren chamberlain darren at boston.com
Tue Aug 13 11:51:43 EDT 2002


* Smylers <smylers at gbdirect.co.uk> [2002-08-13 11:29]:
> Vivek Khera wrote:
> 
> > >>>>> "BC" == Bruce Campbell <bruce_campbell at ripe.net> writes:
> >
> > BC> 	    if ($RTLoop =~ /^\s*$RT::rtname\s*$/ ) {
> >
> > I'm using it but modified a bit for efficiency:
> >
> >     if ($RTLoop =~ m/\s?$RT::rtname\s?/) {
> >
> > since the * is greedy.
> 
> What's wrong with that?  I was always under the impression that greedy
> modifiers are more efficient that non-greedy versions because the greedy
> versions don't involve backtracking.

Here's a potentially helpful benchmark:

  $ perl -MBenchmark -Mstrict
  my $c = 0;
  my $d = 0;
  my $f = "hello world";
  my $pat = "hello";
  timethese( 1_000_000, {
          'anchored_greedy' => sub { if ($f =~ /^\s*\Q$pat\E\s*$/) { $c++ } },
          'unanchored_nongreedy' => sub { if ($f =~ /\s?\Q$pat\E\s?/) { $d++ } },
  });

  Benchmark: timing 1000000 iterations of anchored_greedy, unanchored_nongreedy...
  anchored_greedy:  2 wallclock secs ( 3.36 usr +  0.00 sys =  3.36 CPU) @ 297619.05/s (n=1000000)
  unanchored_nongreedy:  4 wallclock secs ( 3.03 usr +  0.00 sys =  3.03 CPU) @ 330033.00/s (n=1000000)

(darren)

-- 
Hell is other people.
    -- Jean-Paul Sartre




More information about the rt-users mailing list