I'd be interested in seeing your results. I did some some benchmarking
too, and found that the regex is slower.
Here's the program (using my soon to be released 'Benchmark::Sized'
module) and the results.
#!/usr/bin/perl
use strict;
use warnings qw 'all';
use Benchmark::Sized;
use vars qw /@array/;
my $stats = sized_timethese
run_for => 2,
steps => 8,
start_size => 1,
end_size => 1000,
seed => sub {
@main::array = map {join "" => map {chr rand 128} 1 .. $_ [0]}
+ 1 .. 20
},
code => {
regex => 'my @foo = grep {! /^\.\.?\Z/} @main::array',
ne => 'my @foo = grep {$_ ne "." and $_ ne ".."} @main::ar
+ray',
}
;
print "Runs/second for regex vs ne:\n";
print_timed $stats, type => 'sized';
__END__
Runs/second for regex vs ne:
Size ne regex
1: 20744.28 12809.79
3: 22549.51 13048.06
7: 23110.45 12337.91
19: 21600.00 12560.28
52: 21005.50 12276.56
139: 19269.95 11891.63
373: 18345.79 11220.29
1000: 14422.54 9634.74
Abigail
|