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...
In reply to Re: Re: counting regex hits Benchamark
by cees
in thread counting regex hits
by Becky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |