- or download this
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
- or download this
my $pre = 250;
my $post = 250;
- or download this
my $baz_match = ('b' x $pre) . 'baz' . ('b' x $post);
my $bar_match = ('b' x $pre) . 'bar' . ('b' x $post);
my $no_match = ('b' x $pre) . 'bza' . ('b' x $post);
- or download this
my $i;
- or download this
cmpthese( 750000,
{
...
using_alt_nomatch => sub { $i += ($no_match =~ /bar|baz/)
+ ? 1 : 0 },
});
print $i, $/;
- or download this
(warning: too few iterations for a reliable count)
(warning: too few iterations for a reliable count)
...
using_or_nomatch 8333333/s 6533% 3033%
+ -- -33%
using_or_match 12500000/s 9850% 4600%
+ 50% --
500000