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 58 59 60 61 62 63 64 65 66 67
|
#!perl -w
use strict;
use Benchmark qw(:all);
use FindBin qw($Bin);
use lib $Bin;
use Common;
use Data::Util qw(:all);
signeture 'Data::Util' => \&install_subroutine;
my $pkg = do{ package Foo; __PACKAGE__ };
sub foo{ 42 }
print "Installing a subroutine:\n";
cmpthese timethese -1 => {
installer => sub{
no warnings 'redefine';
install_subroutine($pkg, foo => \&foo);
},
direct => sub{
no warnings 'redefine';
no strict 'refs';
*{$pkg . '::foo'} = \&foo;
},
};
print "\nInstalling 2 subroutines:\n";
cmpthese timethese -1 => {
installer => sub{
no warnings 'redefine';
install_subroutine($pkg, foo => \&foo, bar => \&foo);
},
direct => sub{
no warnings 'redefine';
no strict 'refs';
*{$pkg . '::foo'} = \&foo;
*{$pkg . '::bar'} = \&foo;
},
};
print "\nInstalling 4 subroutines:\n";
cmpthese timethese -1 => {
installer => sub{
no warnings 'redefine';
install_subroutine($pkg,
foo => \&foo,
bar => \&foo,
baz => \&foo,
baz => \&foo,
);
},
direct => sub{
no warnings 'redefine';
no strict 'refs';
*{$pkg . '::foo'} = \&foo;
*{$pkg . '::bar'} = \&foo;
*{$pkg . '::baz'} = \&foo;
*{$pkg . '::bax'} = \&foo;
},
};
|