On Jul 27, Paul Tremblay said:

>I ran a benchmark on your method, and it actually proved slower. I ran a
>test line 10,000 times. Directly substituting each line took 38 wall
>seconds. Using your method took 60.

That's because my method requires creating a hash each time.  If you were
to take that out of the function, it would run faster.

Also, the way you've made my hash, the regex looks for "\\& " and changes
it to "<&amp;/>", which is not what the other method does.

My method assumed you would build the hash ONCE and use it for as many
strings as necessary.  If you're only going to DO the work ONCE, there's
no need to make a hash.

Also, you've even slightly exaggerated my method's speed by using the /o
modifier on the regex, since you're building the regex each time.  If you
rewrite it like so:

  my %rep = (
    '\\this ' => '<this/>,
    '&' => '&amp;',
    # ...
  );
  my $rx = join '|', map quotemeta, keys %rep;

  sub hash_method {
    my $l = $line;
    $l =~ s[\\($rx) ][<$rep{$1}/>]go;
  }

Try that instead.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for?  <tenderpuss> why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to