Benchmarking the following multi method:
multi method fib ( Int $i where { $_ <= 1 } ) { return $i; } multi method fib ( Int $i ) { return $self->fib($i-1) + $self->fib($i-2); }
The code that invokes the multi method is:
my $obj = $implementation->new; $obj->fib($_) for 0..10;
Modules tested are:
Kavorka (of course)
MooseX::MultiMethods
Plain old Perl 5 subs, for comparison.
Running perl -Ilib examples/benchmarks-multisub.pl:
perl -Ilib examples/benchmarks-multisub.pl
Rate MXMM Kavorka Plain MXMM 0.861/s -- -89% -100% Kavorka 7.81/s 807% -- -97% Plain 276/s 32026% 3441% --
Kavorka is the faster multi-method implementation, though is significantly slower than avoiding multi-methods.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2013 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Kavorka, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Kavorka
CPAN shell
perl -MCPAN -e shell install Kavorka
For more information on module installation, please visit the detailed CPAN module installation guide.