in reply to Re: counting regex hits Benchamark
in thread counting regex hits
The only thing that I would change is the 'random feature' you put in the benchmark. This will throw off your results, since you are not providing the same value to each function. In the worst case the 'tr' function could get the shortest string and the 'm//' function gets the longest string every time.
Of course this ambiguity would be evened out since you do a million iterations, and I'll bet your results will not change much by fixing this. But, I would replace the random function and just loop through each item in every iteration.
cmpthese(100000, { 'tr' => sub { foreach (@rands) { my $x = tr/-//; } }, 'm//' => sub { foreach (@rands) { my $x = () = $_ =~ /-/g; } }, } );
This way you are guaranteed an even distribution of your sample data.
I agree with you that the results are impressive. Definately something to keep in the bin of useful perl knowledge...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: counting regex hits Benchamark
by Doc Technical (Initiate) on Mar 18, 2003 at 22:48 UTC | |
by Tomte (Priest) on Mar 19, 2003 at 09:17 UTC | |
by Doc Technical (Initiate) on Mar 19, 2003 at 20:05 UTC |