File: install_subr_bench.pl

package info (click to toggle)
libdata-util-perl 0.66-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 564 kB
  • ctags: 164
  • sloc: perl: 2,958; ansic: 416; makefile: 8
file content (67 lines) | stat: -rw-r--r-- 1,186 bytes parent folder | download | duplicates (5)
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;
	},
};