6 use Benchmark qw[timethese];
10 This benchmark is designed to measure how long things with type constraints
11 take (constructors, accessors). It was created to measure the impact of
12 inlining type constraints.
43 isa => 'ArrayRef[Int]',
48 isa => 'ArrayRef[Str]',
53 isa => 'ArrayRef[FileHandle]',
58 isa => 'ArrayRef[Object]',
63 isa => 'HashRef[Int]',
68 isa => 'HashRef[Str]',
73 isa => 'HashRef[FileHandle]',
78 isa => 'HashRef[Object]',
81 __PACKAGE__->meta->make_immutable;
93 __PACKAGE__->meta->make_immutable;
97 my @strs = 'a' .. 'j';
98 my @fhs = map { my $fh; open $fh, '<', $0 or die; $fh; } 1 .. 10;
99 my @objects = map { Thing->new } 1 .. 10;
101 my %ints = map { $_ => $_ } @ints;
102 my %strs = map { $_ => $_ } @ints;
103 my %fhs = map { $_ => $_ } @fhs;
104 my %objects = map { $_ => $_ } @objects;
106 my $thing = Thing->new;
107 my $simple = Simple->new;
111 constructor_simple => sub {
112 Simple->new( str => $strs[0] );
114 accessors_simple => sub {
115 $simple->str( $strs[0] );
122 constructor_all => sub {
127 object => $objects[0],
131 a_object => \@objects,
135 h_object => \%objects,
138 accessors_all => sub {
139 $thing->int( $ints[0] );
140 $thing->str( $strs[0] );
141 $thing->fh( $fhs[0] );
142 $thing->object( $objects[0] );
143 $thing->a_int( \@ints );
144 $thing->a_str( \@strs );
145 $thing->a_fh( \@fhs );
146 $thing->a_object( \@objects );
147 $thing->h_int( \%ints );
148 $thing->h_str( \%strs );
149 $thing->h_fh( \%fhs );
150 $thing->h_object( \%objects );