Forum Moderators: phranque
Would that get caught by that rule?
I benchmarked some expressions in perl and found an anchor at the start only was the worst.
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $str2="example.com";
timethese(10_000_000, {
'startanchor' => sub {
1 unless $str2=~m/^example\.com/;
},
'anchor' => sub {
1 unless $str2=~m/^example\.com$/;
},
'endanchor' => sub {
1 unless $str2=~m/example\.com$/;
},
'float' => sub {
1 unless $str2=~m/example\.com/;
},
});
Benchmark: timing 10000000 iterations of anchor, endanchor, float, startanchor...
anchor: 5 wallclock secs ( 3.81 usr + 0.00 sys = 3.81 CPU) @ 2624671.92/s (n=10000000)
endanchor: 3 wallclock secs ( 2.08 usr + 0.00 sys = 2.08 CPU) @ 4807692.31/s (n=10000000)
float: 1 wallclock secs ( 2.22 usr + 0.00 sys = 2.22 CPU) @ 4504504.50/s (n=10000000)
startanchor: 5 wallclock secs ( 3.43 usr + 0.00 sys = 3.43 CPU) @ 2915451.90/s (n=10000000)
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;
my $str2="example.com";
timethese(10_000_000, {
'startanchor' => sub {
1 unless $str2=~m/^(?:www\.)?example\.com/;
},
'anchor' => sub {
1 unless $str2=~m/^(?:www\.)?example\.com$/;
},
'endanchor' => sub {
1 unless $str2=~m/(?:www\.)?example\.com$/;
},
'float' => sub {
1 unless $str2=~m/(?:www\.)?example\.com/;
},
});
Benchmark: timing 10000000 iterations of anchor, endanchor, float, startanchor...
anchor: 4 wallclock secs ( 3.61 usr + 0.00 sys = 3.61 CPU) @ 2770083.10/s (n=10000000)
endanchor: 3 wallclock secs ( 3.76 usr + 0.00 sys = 3.76 CPU) @ 2659574.47/s (n=10000000)
float: 3 wallclock secs ( 3.33 usr + 0.00 sys = 3.33 CPU) @ 3003003.00/s (n=10000000)
startanchor: 4 wallclock secs ( 3.47 usr + 0.00 sys = 3.47 CPU) @ 2881844.38/s (n=10000000)