1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
|
#!perl -w
use strict;
use Benchmark qw(:all);
use FindBin qw($Bin);
use lib $Bin;
use Common;
use Data::Util qw(:all), @ARGV;
use Params::Util qw(_INVOCANT);
signeture 'Data::Util' => \&is_invocant, 'Params::Util' => \&_INVOCANT;
BEGIN{
package Base;
sub new{
bless {} => shift;
}
package Foo;
our @ISA = qw(Base);
package Foo::X;
our @ISA = qw(Foo);
package Foo::X::X;
our @ISA = qw(Foo::X);
package Foo::X::X::X;
our @ISA = qw(Foo::X::X);
}
print "Benchmark: Data::Util::is_invocant() vs. Params::Util::_INVOCANT() vs. eval{}\n";
foreach my $x (Foo->new, Foo::X::X::X->new(), 'Foo', 'Foo::X::X::X', undef, {}){
print 'For ', neat($x), "\n";
my $i = 0;
cmpthese -1 => {
'eval{}' => sub{
for(1 .. 10){
$i++ if eval{ $x->VERSION; 1 };
}
},
'_INVOCANT' => sub{
for(1 .. 10){
$i++ if _INVOCANT($x);
}
},
'is_invocant' => sub{
for(1 .. 10){
$i++ if is_invocant($x);
}
},
};
print "\n";
}
|