|
|
| Perl: the Markov chain saw | |
| PerlMonks |
Re: Re: Craftierby chipmunk (Parson) |
| on Dec 15, 2000 at 04:30 UTC ( #46767=note: print w/ replies, xml ) | Need Help?? |
|
I'm afraid there are serious problems with the Benchmark code that you posted. It is important to make sure all your code snippets do the right thing before you benchmark them, and to make sure the benchmark itself is doing the right thing. I hope it will be instructive if I detail the issues. There are two problems with the tr/// solution; \s is not special inside tr///, and /d is required for tr/// to delete characters. There are also two problems with the split solution; you are splitting $_ using $junk as the delimiter, and you are joining with a space instead of a null string. There are also problems with the benchmark itself. $junk is a lexical, so it is not accessible from the Benchmark module. Since you passed quoted strings, your snippets were compiled in the Benchmark module and were operating on an empty $junk. Once that problem is fixed, since each code snippet modifies $junk in place, only the first execution of the first snippet would have any work to do; all the remaining iterations would be processing a string that had already been stripped of whitespace. Here is an improved benchmark: and the new results are: As you can see, the translation solution is actually the big winner, and the substitution is only 1.5 times as fast as split/join.
In Section
Meditations
|
|
||||||||||||||||||||||||||||