#!/usr/bin/perl use strict; use warnings; use Benchmark qw(cmpthese); #### my $pre = 250; my $post = 250; #### 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); #### my $i; #### cmpthese( 750000, { using_or_match => sub { $i += ($baz_match =~ /bar/ or $baz_match =~ /baz/) ? 1 : 0 }, using_or_nomatch => sub { $i += ($no_match =~ /bar/ or $no_match =~ /baz/) ? 1 : 0 }, using_alt_match => sub { $i += ($baz_match =~ /bar|baz/) ? 1 : 0 }, using_alt_nomatch => sub { $i += ($no_match =~ /bar|baz/) ? 1 : 0 }, }); print $i, $/; #### (warning: too few iterations for a reliable count) (warning: too few iterations for a reliable count) Rate using_alt_nomatch using_alt_match using_or_nomatch using_or_match using_alt_nomatch 125628/s -- -53% -98% -99% using_alt_match 265957/s 112% -- -97% -98% using_or_nomatch 8333333/s 6533% 3033% -- -33% using_or_match 12500000/s 9850% 4600% 50% -- 500000