On Sat, Jul 27, 2002 at 11:23:59AM -0400, Jeff 'japhy' Pinyan wrote:
> 
> 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.

Right. This makes perfect sense.

I  followed your advice and put the hash outside of the subroutine. I
also took out the ampersand substitution to make things equal.

I got some interesting resulst. If I used a long line full of tokens,
then each method was as fast. But if I used a more represenative line with
just a few tokens, then your method was around twice as fast. 

That makes sense. The "read_each_line" method has to read the non-tokens
35 times (once for each substitution). You method gets to skip over
them.

If I used a line with no tokens, your method ran 10 times faster. That's
why your suggestion above:

'\\this ' => '<this/>,

might not be a good idea. If I wrote my hash like this, then as perl
searches the line, it has to search each item in the hash. Your
original suggestion looked like this:

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

With this method, perl stops searching if it doesn't find a "\".
That means it can skip over lines with no "\", which in turn means that
it will run around 10 times faster than using my original method.

The only problem is how I should replace "&", ">", and "<". I think I'll
do single line subs for this text. Even with huge files it shouldn't
take more than 1/2 a second or so, and that allows me to use your
original method to speed things up.

Or this just occurred to me:

s[(&)|(<)|(>)|\\($rx)][<$rep{$1}/>]go;

Yea, that should work!

I also realize that I shouldn't initialize my hashes in my subroutines.
Making them global should also speed up my script a bit.

Thanks!

Paul

-- 

************************
*Paul Tremblay         *
*[EMAIL PROTECTED]*
************************

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

Reply via email to