Help for this page

Select Code to Download


  1. or download this
    #!/usr/bin/perl
    use strict;
    use warnings;
    use Benchmark qw(cmpthese);
    
  2. or download this
    my $pre = 250;
    my $post = 250;
    
  3. 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);
    
  4. or download this
    my $i;
    
  5. or download this
    cmpthese( 750000,
             {
    ...
                 using_alt_nomatch => sub { $i += ($no_match =~ /bar|baz/)
    + ? 1 : 0 },
             });
    print $i, $/;
    
  6. 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