September 2011 Archives

Playing around with Method::Signatures::Simple

Method::Signatures::Simple: Nice, very simple, and almost as fast as pure perl, is this module ready for use in modules you depend on?

package Test;

use Method::Signatures::Simple;
use Benchmark qw/:all/ ;


sub new {
    bless {}, shift;
}


# with Method::Signatures::Simple
method signatures ($first, $second) {
    die unless $self;
    die unless $first;
    die unless $second;
}


# default perl
sub default {
    my $self = shift;
    my ($first, $second) = @_;

    die unless $self;
    die unless $first;
    die unless $second;
}


# some benchmarking
my $self = __PACKAGE__->new;

my $call_signatures = sub {
    $self->signatures(1,2)
};

my $call_default = sub {
    $self->default(1,2)
};


cmpthese(10000000, {
    'Signatures' => $call_signatures,
    'Default'    => $call_default
});

Results:

                Rate    Default Signatures
Default    1316309/s         --        -8%
Signatures 1434103/s         9%         --

About Forward Ever

user-pic I blog about Perl.