On 8/27/07, Chas Owens <[EMAIL PROTECTED]> wrote:
snip
>           Rate   join   hard joinqr    opt     qr
> join   42708/s     --    -0%    -1%   -11%   -56%
> hard   42708/s     0%     --    -1%   -11%   -56%
> joinqr 43115/s     1%     1%     --   -11%   -56%
> opt    48188/s    13%    13%    12%     --   -50%
> qr     97303/s   128%   128%   126%   102%     --
snip

Somehow I lost the top of the benchmark program, here it is in full:

#!/usr/bin/perl

use strict;
use warnings;
use Benchmark;

my @replace = (
       #replace   with
       [ qr/foo/, 'Foo' ],
       [ qr/bar/, 'Bar' ],
       [ qr/baz/, 'Baz' ]
);

my %replace = (
        foo => "Foo",
        bar => "Bar",
        baz => "Baz"
);

my $str = join '|', keys %replace;
my $re  = qr/$str/;

my $text = "This is a test of replacements for foo,
bar, and baz.  The output should have
foo looking like Foo, bar looking like
Bar, and likewise for baz.";
my %subs = (
        'qr' => sub {
                my $t = $text;
                $t =~ s/$_->[0]/$_->[1]/g for @replace;
                return $t;
        },
        joinqr => sub {
                my $t = $text;
                $t =~ s/($re)/$replace{$1}/g;
                return $t;
        },
        join => sub {
                my $t = $text;
                $t =~ s/($str)/$replace{$1}/g;
                return $t;
        },
        hard => sub {
                my $t = $text;
                $t =~ s/(foo|bar|baz)/$replace{$1}/g;
                return $t;
        },
        opt =>  sub {
                my $t = $text;
                $t =~ s/(foo|ba[rz])/$replace{$1}/g;
                return $t;
        }
);

Benchmark::cmpthese(-1, \%subs);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to