Benchmark-Perl-Formance

 view release on metacpan or  search on metacpan

lib/Benchmark/Perl/Formance/Plugin/RxCmp.pm  view on Meta::CPAN

{
        my ($options) = @_;

        my $result;
        my $reg = qr/$re/o;
        my $t = timeit $count, sub { $result = $string =~ $reg };
        return {
                Benchmark             => $t,
                goal                  => $goal,
                count                 => $count,
                result                => $result,
                # string                => $string,
                # re                    => $re,
                used_qr_or_precompile => 1,
               };
}

sub POSIX
{
        my ($options) = @_;

        my $reg;
        ## no critic
        eval '
                use POSIX::Regex qw(:all);
                $reg = POSIX::Regex->new($re, REG_EXTENDED);
        ';
        ## use critic
        if ($@) {
                print STDERR "# ".$@ if $options->{verbose} > 2;
                return { failed => "use failed" };
        }


        my $result;
        my $t = timeit $count, sub { $result = $reg->match($string) };
        return {
                Benchmark             => $t,
                goal                  => $goal,
                count                 => $count,
                result                => $result,
                # string                => $string,
                # re                    => $re,
                used_qr_or_precompile => 1,
               };
}

sub LPeg
{
        my ($options) = @_;

        # LPEG regexes seemingly don't work the same way as usual regexes
        # therefore the pattern below does not match.
        # TODO: Find a equivalent pattern.
        eval "use re::engine::LPEG"; ## no critic
        if ($@) {
                print STDERR "# ".$@ if $options->{verbose} > 2;
                return { failed => "use failed" };
        }

        return { not_yet_implemented => 'missing comparable equivalent regex' };

        my $result;
        my $re_local = ("'a'?" x $n) . ("'a'" x $n);
        #my $reg      = qr/$re_local/; # using that $reg later segfaults
        my $t = timeit $count, sub { $result = $string =~ /$re_local/ };
        return {
                Benchmark             => $t,
                goal                  => $goal,
                count                 => $count,
                result                => $result,
                # string                => $string,
                # re                    => $re_local,
                used_qr_or_precompile => 0,
               };
}

sub Lua
{
        my ($options) = @_;

        # LPEG regexes seemingly don't work the same way as usual regexes
        # therefore the pattern below does not match.
        # TODO: Find a equivalent pattern.
        # return { not_yet_implemented => 'need to find a equivalent pattern' };

        eval "use re::engine::Lua"; ## no critic
        if ($@) {
                print STDERR "# ".$@ if $options->{verbose} > 2;
                return { failed => "use failed" };
        }

        my $result;
        #my $reg      = qr/$re/; # using that $reg later segfaults, unfortunately that makes
        my $t = timeit $count, sub { $result = $string =~ /$re/ };
        return {
                Benchmark             => $t,
                goal                  => $goal,
                count                 => $count,
                result                => $result,
                # string                => $string,
                # re                    => $re,
                used_qr_or_precompile => 0,
               };
}

sub PCRE
{
        my ($options) = @_;

        eval "use re::engine::PCRE"; ## no critic
        if ($@) {
                print STDERR "# ".$@ if $options->{verbose} > 2;
                return { failed => "use failed" };
        }

        my $result;
        my $reg = qr/$re/o;
        my $t = timeit $count, sub { $result = $string =~ $reg };
        return {
                Benchmark => $t,
                goal      => $goal,
                count     => $count,
                result    => $result,
                # string    => $string,
                # re        => $re_local,
                used_qr_or_precompile => 1,
               };
}

sub RE2
{
        my ($options) = @_;

        eval "use re::engine::RE2"; ## no critic
        if ($@) {
                print STDERR "# ".$@ if $options->{verbose} > 2;
                return { failed => "use failed" };
        }

        my $result;
        my $reg = qr/$re/o;
        my $t = timeit $count, sub { $result = $string =~ $reg };
        return {
                Benchmark => $t,



( run in 1.262 second using v1.01-cache-2.11-cpan-39bf76dae61 )